summaryrefslogtreecommitdiff
path: root/apps/plugins/lua/rockaux.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/lua/rockaux.c')
-rw-r--r--apps/plugins/lua/rockaux.c22
1 files changed, 7 insertions, 15 deletions
diff --git a/apps/plugins/lua/rockaux.c b/apps/plugins/lua/rockaux.c
index f10a1cb021..b51364f718 100644
--- a/apps/plugins/lua/rockaux.c
+++ b/apps/plugins/lua/rockaux.c
@@ -73,9 +73,8 @@ int strcoll(const char * str1, const char * str2)
73 return rb->strcmp(str1, str2); 73 return rb->strcmp(str1, str2);
74} 74}
75 75
76const char* get_current_path(lua_State *L, int level) 76int get_current_path(lua_State *L, int level)
77{ 77{
78 static char buffer[MAX_PATH];
79 lua_Debug ar; 78 lua_Debug ar;
80 79
81 if(lua_getstack(L, level, &ar)) 80 if(lua_getstack(L, level, &ar))
@@ -84,22 +83,15 @@ const char* get_current_path(lua_State *L, int level)
84 and write it to dest. */ 83 and write it to dest. */
85 lua_getinfo(L, "S", &ar); 84 lua_getinfo(L, "S", &ar);
86 85
87 char* curfile = (char*) &ar.source[1]; 86 const char* curfile = &ar.source[1];
88 char* pos = rb->strrchr(curfile, '/'); 87 const char* pos = rb->strrchr(curfile, '/');
89 if(pos != NULL) 88 if(pos != NULL)
90 { 89 {
91 unsigned int len = (unsigned int)(pos - curfile); 90 lua_pushlstring (L, curfile, pos - curfile + 1);
92 len = len + 1 > sizeof(buffer) ? sizeof(buffer) - 1 : len; 91 return 1;
93
94 if(len > 0)
95 memcpy(buffer, curfile, len);
96
97 buffer[len] = '/';
98 buffer[len+1] = '\0';
99
100 return buffer;
101 } 92 }
102 } 93 }
103 94
104 return NULL; 95 lua_pushnil(L);
96 return 1;
105} 97}