summaryrefslogtreecommitdiffstats
path: root/apps/plugins/lua/lauxlib.c
diff options
context:
space:
mode:
authorMaurus Cuelenaere <mcuelenaere@gmail.com>2009-06-01 22:31:32 +0000
committerMaurus Cuelenaere <mcuelenaere@gmail.com>2009-06-01 22:31:32 +0000
commit9c3e679d188ec6c117a33ef280d81943a8e37bc8 (patch)
tree5f012e940b9f0bb4540806e9744eab1bf88ad91b /apps/plugins/lua/lauxlib.c
parent82eea9ed69886a4eaf41a1124b292635ca60fe9a (diff)
downloadrockbox-9c3e679d188ec6c117a33ef280d81943a8e37bc8.tar.gz
rockbox-9c3e679d188ec6c117a33ef280d81943a8e37bc8.tar.bz2
rockbox-9c3e679d188ec6c117a33ef280d81943a8e37bc8.zip
Lua: add touchscreen_set_mode & current_path (+ some constants)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21165 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/lua/lauxlib.c')
-rw-r--r--apps/plugins/lua/lauxlib.c48
1 files changed, 27 insertions, 21 deletions
diff --git a/apps/plugins/lua/lauxlib.c b/apps/plugins/lua/lauxlib.c
index fd71e07217..3f6d8e6f1b 100644
--- a/apps/plugins/lua/lauxlib.c
+++ b/apps/plugins/lua/lauxlib.c
@@ -560,24 +560,35 @@ static int errfile (lua_State *L, const char *what, int fnameindex) {
return LUA_ERRFILE;
}
-static void make_path(char* dest, size_t dest_size, char* curfile, char* newfile)
+bool get_cur_path(lua_State *L, char* dest, size_t dest_size)
{
- char* pos = rb->strrchr(curfile, '/');
- if(pos != NULL)
+ lua_Debug ar;
+ if(lua_getstack(L, 1, &ar))
{
- unsigned int len = (unsigned int)(pos - curfile);
- len = len + 1 > dest_size ? dest_size - 1 : len;
-
- if(len > 0)
- memcpy(dest, curfile, len);
-
- dest[len] = '/';
- dest[len+1] = '\0';
+ /* 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 > dest_size ? dest_size - 1 : len;
+
+ if(len > 0)
+ memcpy(dest, curfile, len);
+
+ dest[len] = '/';
+ dest[len+1] = '\0';
+
+ return true;
+ }
+ else
+ return false;
}
else
- dest[0] = '\0';
-
- strncat(dest, newfile, dest_size - strlen(dest));
+ return false;
}
LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) {
@@ -590,13 +601,8 @@ LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) {
if(lf.f < 0) {
/* Fallback */
- lua_Debug ar;
- if(lua_getstack(L, 1, &ar)) {
- lua_getinfo(L, "S", &ar);
-
- /* Try determining the base path of the current Lua chunk
- and prepend it to filename in buffer. */
- make_path(buffer, sizeof(buffer), (char*)&ar.source[1], (char*)filename);
+ if(get_cur_path(L, buffer, sizeof(buffer))) {
+ strncat(buffer, filename, sizeof(buffer) - strlen(buffer));
lf.f = rb->open(buffer, O_RDONLY);
}