summaryrefslogtreecommitdiff
path: root/apps/plugins/lua/rocklib.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/lua/rocklib.c')
-rw-r--r--apps/plugins/lua/rocklib.c32
1 files changed, 6 insertions, 26 deletions
diff --git a/apps/plugins/lua/rocklib.c b/apps/plugins/lua/rocklib.c
index 5109092570..410916b2f9 100644
--- a/apps/plugins/lua/rocklib.c
+++ b/apps/plugins/lua/rocklib.c
@@ -782,34 +782,14 @@ RB_WRAP(read_bmp_file)
782 782
783RB_WRAP(current_path) 783RB_WRAP(current_path)
784{ 784{
785 char buffer[MAX_PATH]; 785 const char *current_path = get_current_path(L, 1);
786 lua_Debug ar; 786 if(current_path != NULL)
787
788 if(lua_getstack(L, 1, &ar))
789 { 787 {
790 /* Try determining the base path of the current Lua chunk 788 lua_pushstring(L, current_path);
791 and write it to dest. */ 789 return 1;
792 lua_getinfo(L, "S", &ar);
793
794 char* curfile = (char*) &ar.source[1];
795 char* pos = rb->strrchr(curfile, '/');
796 if(pos != NULL)
797 {
798 unsigned int len = (unsigned int)(pos - curfile);
799 len = len + 1 > sizeof(buffer) ? sizeof(buffer) - 1 : len;
800
801 if(len > 0)
802 memcpy(buffer, curfile, len);
803
804 buffer[len] = '/';
805 buffer[len+1] = '\0';
806
807 lua_pushstring(L, buffer);
808 return 1;
809 }
810 } 790 }
811 791 else
812 return 0; 792 return 0;
813} 793}
814 794
815#define R(NAME) {#NAME, rock_##NAME} 795#define R(NAME) {#NAME, rock_##NAME}