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.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/apps/plugins/lua/rocklib.c b/apps/plugins/lua/rocklib.c
index a3a42af9f6..f22bd01b48 100644
--- a/apps/plugins/lua/rocklib.c
+++ b/apps/plugins/lua/rocklib.c
@@ -866,13 +866,33 @@ RB_WRAP(read_bmp_file)
866RB_WRAP(current_path) 866RB_WRAP(current_path)
867{ 867{
868 char buffer[MAX_PATH]; 868 char buffer[MAX_PATH];
869 if(get_cur_path(L, buffer, sizeof(buffer))) 869 lua_Debug ar;
870
871 if(lua_getstack(L, 1, &ar))
870 { 872 {
871 lua_pushstring(L, buffer); 873 /* Try determining the base path of the current Lua chunk
872 return 1; 874 and write it to dest. */
875 lua_getinfo(L, "S", &ar);
876
877 char* curfile = (char*) &ar.source[1];
878 char* pos = rb->strrchr(curfile, '/');
879 if(pos != NULL)
880 {
881 unsigned int len = (unsigned int)(pos - curfile);
882 len = len + 1 > sizeof(buffer) ? sizeof(buffer) - 1 : len;
883
884 if(len > 0)
885 memcpy(buffer, curfile, len);
886
887 buffer[len] = '/';
888 buffer[len+1] = '\0';
889
890 lua_pushstring(L, buffer);
891 return 1;
892 }
873 } 893 }
874 else 894
875 return 0; 895 return 0;
876} 896}
877 897
878#define R(NAME) {#NAME, rock_##NAME} 898#define R(NAME) {#NAME, rock_##NAME}