diff options
Diffstat (limited to 'apps/plugins/lua/rockaux.c')
-rw-r--r-- | apps/plugins/lua/rockaux.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/apps/plugins/lua/rockaux.c b/apps/plugins/lua/rockaux.c index 11433f286f..95f2ab169b 100644 --- a/apps/plugins/lua/rockaux.c +++ b/apps/plugins/lua/rockaux.c | |||
@@ -21,6 +21,8 @@ | |||
21 | ****************************************************************************/ | 21 | ****************************************************************************/ |
22 | 22 | ||
23 | #include "plugin.h" | 23 | #include "plugin.h" |
24 | #define _ROCKCONF_H_ /* Protect against unwanted include */ | ||
25 | #include "lua.h" | ||
24 | 26 | ||
25 | #if !defined(SIMULATOR) || defined(__MINGW32__) || defined(__CYGWIN__) | 27 | #if !defined(SIMULATOR) || defined(__MINGW32__) || defined(__CYGWIN__) |
26 | int errno = 0; | 28 | int errno = 0; |
@@ -59,3 +61,34 @@ int strcoll(const char * str1, const char * str2) | |||
59 | return rb->strcmp(str1, str2); | 61 | return rb->strcmp(str1, str2); |
60 | } | 62 | } |
61 | 63 | ||
64 | const char* get_current_path(lua_State *L, int level) | ||
65 | { | ||
66 | static char buffer[MAX_PATH]; | ||
67 | lua_Debug ar; | ||
68 | |||
69 | if(lua_getstack(L, level, &ar)) | ||
70 | { | ||
71 | /* Try determining the base path of the current Lua chunk | ||
72 | and write it to dest. */ | ||
73 | lua_getinfo(L, "S", &ar); | ||
74 | |||
75 | char* curfile = (char*) &ar.source[1]; | ||
76 | char* pos = rb->strrchr(curfile, '/'); | ||
77 | if(pos != NULL) | ||
78 | { | ||
79 | unsigned int len = (unsigned int)(pos - curfile); | ||
80 | len = len + 1 > sizeof(buffer) ? sizeof(buffer) - 1 : len; | ||
81 | |||
82 | if(len > 0) | ||
83 | memcpy(buffer, curfile, len); | ||
84 | |||
85 | buffer[len] = '/'; | ||
86 | buffer[len+1] = '\0'; | ||
87 | |||
88 | return buffer; | ||
89 | } | ||
90 | } | ||
91 | |||
92 | return NULL; | ||
93 | } | ||
94 | |||