summaryrefslogtreecommitdiff
path: root/apps/plugins/lua/rockaux.c
diff options
context:
space:
mode:
authorMaurus Cuelenaere <mcuelenaere@gmail.com>2009-07-01 17:01:22 +0000
committerMaurus Cuelenaere <mcuelenaere@gmail.com>2009-07-01 17:01:22 +0000
commit9bff845b49e277af46d6b7a09bb111472f3d3f49 (patch)
tree8277c6a4b2ac95c231ad249b63bf30ab11869a37 /apps/plugins/lua/rockaux.c
parentd5180f7870643e19c37b62909d0e0c545cc23337 (diff)
downloadrockbox-9bff845b49e277af46d6b7a09bb111472f3d3f49.zip
rockbox-9bff845b49e277af46d6b7a09bb111472f3d3f49.tar.gz
rockbox-9bff845b49e277af46d6b7a09bb111472f3d3f49.tar.bz2
rockbox-9bff845b49e277af46d6b7a09bb111472f3d3f49.tar.xz
Lua: because Rockbox doesn't support any current working directory functionality, 'hack' loadlib so it replace '$' in LUA_PATH_DEFAULT with the directory wherein the current script is.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21595 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/lua/rockaux.c')
-rw-r--r--apps/plugins/lua/rockaux.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/apps/plugins/lua/rockaux.c b/apps/plugins/lua/rockaux.c
index 11433f2..95f2ab1 100644
--- a/apps/plugins/lua/rockaux.c
+++ b/apps/plugins/lua/rockaux.c
@@ -21,6 +21,8 @@
****************************************************************************/
#include "plugin.h"
+#define _ROCKCONF_H_ /* Protect against unwanted include */
+#include "lua.h"
#if !defined(SIMULATOR) || defined(__MINGW32__) || defined(__CYGWIN__)
int errno = 0;
@@ -59,3 +61,34 @@ int strcoll(const char * str1, const char * str2)
return rb->strcmp(str1, str2);
}
+const char* get_current_path(lua_State *L, int level)
+{
+ static char buffer[MAX_PATH];
+ lua_Debug ar;
+
+ if(lua_getstack(L, level, &ar))
+ {
+ /* Try determining the base path of the current Lua chunk
+ and write it to dest. */
+ lua_getinfo(L, "S", &ar);
+
+ char* curfile = (char*) &ar.source[1];
+ char* pos = rb->strrchr(curfile, '/');
+ if(pos != NULL)
+ {
+ unsigned int len = (unsigned int)(pos - curfile);
+ len = len + 1 > sizeof(buffer) ? sizeof(buffer) - 1 : len;
+
+ if(len > 0)
+ memcpy(buffer, curfile, len);
+
+ buffer[len] = '/';
+ buffer[len+1] = '\0';
+
+ return buffer;
+ }
+ }
+
+ return NULL;
+}
+