mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-13 18:17:39 -04:00
Lua: add touchscreen_set_mode & current_path (+ some constants)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21165 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
82eea9ed69
commit
9c3e679d18
3 changed files with 59 additions and 20 deletions
|
@ -560,24 +560,35 @@ static int errfile (lua_State *L, const char *what, int fnameindex) {
|
||||||
return LUA_ERRFILE;
|
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, '/');
|
lua_Debug ar;
|
||||||
if(pos != NULL)
|
if(lua_getstack(L, 1, &ar))
|
||||||
{
|
{
|
||||||
unsigned int len = (unsigned int)(pos - curfile);
|
/* Try determining the base path of the current Lua chunk
|
||||||
len = len + 1 > dest_size ? dest_size - 1 : len;
|
and write it to dest. */
|
||||||
|
lua_getinfo(L, "S", &ar);
|
||||||
|
|
||||||
if(len > 0)
|
char* curfile = (char*) &ar.source[1];
|
||||||
memcpy(dest, curfile, len);
|
char* pos = rb->strrchr(curfile, '/');
|
||||||
|
if(pos != NULL)
|
||||||
|
{
|
||||||
|
unsigned int len = (unsigned int)(pos - curfile);
|
||||||
|
len = len + 1 > dest_size ? dest_size - 1 : len;
|
||||||
|
|
||||||
dest[len] = '/';
|
if(len > 0)
|
||||||
dest[len+1] = '\0';
|
memcpy(dest, curfile, len);
|
||||||
|
|
||||||
|
dest[len] = '/';
|
||||||
|
dest[len+1] = '\0';
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
dest[0] = '\0';
|
return false;
|
||||||
|
|
||||||
strncat(dest, newfile, dest_size - strlen(dest));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) {
|
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) {
|
if(lf.f < 0) {
|
||||||
/* Fallback */
|
/* Fallback */
|
||||||
|
|
||||||
lua_Debug ar;
|
if(get_cur_path(L, buffer, sizeof(buffer))) {
|
||||||
if(lua_getstack(L, 1, &ar)) {
|
strncat(buffer, filename, sizeof(buffer) - strlen(buffer));
|
||||||
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);
|
|
||||||
lf.f = rb->open(buffer, O_RDONLY);
|
lf.f = rb->open(buffer, O_RDONLY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -619,6 +619,15 @@ RB_WRAP(kbd_input)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_TOUCHSCREEN
|
||||||
|
RB_WRAP(touchscreen_set_mode)
|
||||||
|
{
|
||||||
|
enum touchscreen_mode mode = luaL_checkint(L, 1);
|
||||||
|
rb->touchscreen_set_mode(mode);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
RB_WRAP(backlight_on)
|
RB_WRAP(backlight_on)
|
||||||
{
|
{
|
||||||
(void)L;
|
(void)L;
|
||||||
|
@ -827,6 +836,18 @@ RB_WRAP(read_bmp_file)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RB_WRAP(current_path)
|
||||||
|
{
|
||||||
|
char buffer[MAX_PATH];
|
||||||
|
if(get_cur_path(L, buffer, sizeof(buffer)))
|
||||||
|
{
|
||||||
|
lua_pushstring(L, buffer);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
#define R(NAME) {#NAME, rock_##NAME}
|
#define R(NAME) {#NAME, rock_##NAME}
|
||||||
static const luaL_Reg rocklib[] =
|
static const luaL_Reg rocklib[] =
|
||||||
{
|
{
|
||||||
|
@ -901,6 +922,7 @@ static const luaL_Reg rocklib[] =
|
||||||
R(action_userabort),
|
R(action_userabort),
|
||||||
#ifdef HAVE_TOUCHSCREEN
|
#ifdef HAVE_TOUCHSCREEN
|
||||||
R(action_get_touchscreen_press),
|
R(action_get_touchscreen_press),
|
||||||
|
R(touchscreen_set_mode),
|
||||||
#endif
|
#endif
|
||||||
R(kbd_input),
|
R(kbd_input),
|
||||||
|
|
||||||
|
@ -916,6 +938,7 @@ static const luaL_Reg rocklib[] =
|
||||||
R(read_bmp_file),
|
R(read_bmp_file),
|
||||||
R(set_viewport),
|
R(set_viewport),
|
||||||
R(clear_viewport),
|
R(clear_viewport),
|
||||||
|
R(current_path),
|
||||||
|
|
||||||
{"new_image", rli_new},
|
{"new_image", rli_new},
|
||||||
|
|
||||||
|
@ -945,10 +968,19 @@ LUALIB_API int luaopen_rock(lua_State *L)
|
||||||
RB_CONSTANT(SEEK_SET);
|
RB_CONSTANT(SEEK_SET);
|
||||||
RB_CONSTANT(SEEK_CUR);
|
RB_CONSTANT(SEEK_CUR);
|
||||||
RB_CONSTANT(SEEK_END);
|
RB_CONSTANT(SEEK_END);
|
||||||
|
|
||||||
RB_CONSTANT(FONT_SYSFIXED);
|
RB_CONSTANT(FONT_SYSFIXED);
|
||||||
RB_CONSTANT(FONT_UI);
|
RB_CONSTANT(FONT_UI);
|
||||||
|
|
||||||
|
#ifdef HAVE_TOUCHSCREEN
|
||||||
|
RB_CONSTANT(TOUCHSCREEN_POINT);
|
||||||
|
RB_CONSTANT(TOUCHSCREEN_BUTTON);
|
||||||
|
RB_CONSTANT(BUTTON_TOUCHSCREEN);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
RB_CONSTANT(BUTTON_REL);
|
||||||
|
RB_CONSTANT(BUTTON_REPEAT);
|
||||||
|
|
||||||
rli_init(L);
|
rli_init(L);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
#define LUA_ROCKLIBNAME "rb"
|
#define LUA_ROCKLIBNAME "rb"
|
||||||
LUALIB_API int (luaopen_rock) (lua_State *L);
|
LUALIB_API int (luaopen_rock) (lua_State *L);
|
||||||
|
bool get_cur_path(lua_State *L, char* dest, size_t dest_size);
|
||||||
|
|
||||||
#endif /* _ROCKLIB_H_ */
|
#endif /* _ROCKLIB_H_ */
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue