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
This commit is contained in:
Maurus Cuelenaere 2009-07-01 17:01:22 +00:00
parent d5180f7870
commit 9bff845b49
5 changed files with 44 additions and 29 deletions

View file

@ -782,34 +782,14 @@ RB_WRAP(read_bmp_file)
RB_WRAP(current_path)
{
char buffer[MAX_PATH];
lua_Debug ar;
if(lua_getstack(L, 1, &ar))
const char *current_path = get_current_path(L, 1);
if(current_path != NULL)
{
/* 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;
}
lua_pushstring(L, current_path);
return 1;
}
return 0;
else
return 0;
}
#define R(NAME) {#NAME, rock_##NAME}