diff options
| author | Maurus Cuelenaere <mcuelenaere@gmail.com> | 2009-06-25 13:26:05 +0000 |
|---|---|---|
| committer | Maurus Cuelenaere <mcuelenaere@gmail.com> | 2009-06-25 13:26:05 +0000 |
| commit | 3ff84e5e4ff402b550b7fa768e010a3586dded10 (patch) | |
| tree | 34a6c480c7ce02063ebb22c1c1e73d41b0fb7073 /apps/plugins/lua/rocklib.c | |
| parent | 48f4512518c60456d02b3802d0bae41e6095ec21 (diff) | |
| download | rockbox-3ff84e5e4ff402b550b7fa768e010a3586dded10.zip rockbox-3ff84e5e4ff402b550b7fa768e010a3586dded10.tar.gz rockbox-3ff84e5e4ff402b550b7fa768e010a3586dded10.tar.bz2 rockbox-3ff84e5e4ff402b550b7fa768e010a3586dded10.tar.xz | |
Lua: add the package library
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21506 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/lua/rocklib.c')
| -rw-r--r-- | apps/plugins/lua/rocklib.c | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/apps/plugins/lua/rocklib.c b/apps/plugins/lua/rocklib.c index a3a42af..f22bd01 100644 --- a/apps/plugins/lua/rocklib.c +++ b/apps/plugins/lua/rocklib.c @@ -866,13 +866,33 @@ RB_WRAP(read_bmp_file) RB_WRAP(current_path) { char buffer[MAX_PATH]; - if(get_cur_path(L, buffer, sizeof(buffer))) + lua_Debug ar; + + if(lua_getstack(L, 1, &ar)) { - lua_pushstring(L, buffer); - return 1; + /* 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'; + + lua_pushstring(L, buffer); + return 1; + } } - else - return 0; + + return 0; } #define R(NAME) {#NAME, rock_##NAME} |