mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-14 02:27:39 -04:00
Lua:
* add action_get_touchscreen_press wrapper * fix kbd_input wrapper * rework luaL_loadfile * add rb.contexts git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21046 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
475b5dc2bb
commit
0f7e4e36ae
6 changed files with 105 additions and 74 deletions
|
@ -644,6 +644,10 @@ static const struct plugin_api rockbox_api = {
|
||||||
appsversion,
|
appsversion,
|
||||||
/* new stuff at the end, sort into place next time
|
/* new stuff at the end, sort into place next time
|
||||||
the API gets incompatible */
|
the API gets incompatible */
|
||||||
|
|
||||||
|
#ifdef HAVE_TOUCHSCREEN
|
||||||
|
action_get_touchscreen_press,
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
int plugin_load(const char* plugin, const void* parameter)
|
int plugin_load(const char* plugin, const void* parameter)
|
||||||
|
|
|
@ -128,7 +128,7 @@ void* plugin_get_buffer(size_t *buffer_size);
|
||||||
#define PLUGIN_MAGIC 0x526F634B /* RocK */
|
#define PLUGIN_MAGIC 0x526F634B /* RocK */
|
||||||
|
|
||||||
/* increase this every time the api struct changes */
|
/* increase this every time the api struct changes */
|
||||||
#define PLUGIN_API_VERSION 151
|
#define PLUGIN_API_VERSION 152
|
||||||
|
|
||||||
/* update this to latest version if a change to the api struct breaks
|
/* update this to latest version if a change to the api struct breaks
|
||||||
backwards compatibility (and please take the opportunity to sort in any
|
backwards compatibility (and please take the opportunity to sort in any
|
||||||
|
@ -806,6 +806,10 @@ struct plugin_api {
|
||||||
const char *appsversion;
|
const char *appsversion;
|
||||||
/* new stuff at the end, sort into place next time
|
/* new stuff at the end, sort into place next time
|
||||||
the API gets incompatible */
|
the API gets incompatible */
|
||||||
|
|
||||||
|
#ifdef HAVE_TOUCHSCREEN
|
||||||
|
int (*action_get_touchscreen_press)(short *x, short *y);
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
/* plugin header */
|
/* plugin header */
|
||||||
|
|
|
@ -22,21 +22,38 @@ $input = $ARGV[0] . "/../../action.h";
|
||||||
|
|
||||||
open(ACTION, "<$input") or die "Can't open $input!";
|
open(ACTION, "<$input") or die "Can't open $input!";
|
||||||
|
|
||||||
print "-- Don't change this file!\n";
|
|
||||||
print "-- It is automatically generated of action.h\n";
|
|
||||||
print "rb.actions = {\n";
|
|
||||||
|
|
||||||
$i = 0;
|
$i = 0;
|
||||||
|
$j = 0;
|
||||||
while(my $line = <ACTION>)
|
while(my $line = <ACTION>)
|
||||||
{
|
{
|
||||||
chomp($line);
|
chomp($line);
|
||||||
if($line =~ /^\s*(ACTION_[^\s]+)(\s*=.*)?,$/)
|
if($line =~ /^\s*(ACTION_[^\s]+)(\s*=.*)?,\s*$/)
|
||||||
{
|
{
|
||||||
printf "\t%s = %d,\n", $1, $i;
|
$actions[$i] = sprintf("\t%s = %d,\n", $1, $i);
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
elsif($line =~ /^\s*(CONTEXT_[^\s]+)(\s*=.*)?,\s*$/)
|
||||||
|
{
|
||||||
|
$contexts[$j] = sprintf("\t%s = %d,\n", $1, $j);
|
||||||
|
$j++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
close(ACTION);
|
||||||
|
|
||||||
|
print "-- Don't change this file!\n";
|
||||||
|
printf "-- It is automatically generated of action.h %s\n", '$Revision';
|
||||||
|
|
||||||
|
print "rb.actions = {\n";
|
||||||
|
foreach $action(@actions)
|
||||||
|
{
|
||||||
|
print $action;
|
||||||
|
}
|
||||||
print "}\n";
|
print "}\n";
|
||||||
|
|
||||||
close(ACTION);
|
print "rb.contexts = {\n";
|
||||||
|
foreach $context(@contexts)
|
||||||
|
{
|
||||||
|
print $context;
|
||||||
|
}
|
||||||
|
print "}\n";
|
||||||
|
|
|
@ -547,60 +547,62 @@ 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)
|
||||||
|
{
|
||||||
|
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';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
dest[0] = '\0';
|
||||||
|
|
||||||
|
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) {
|
||||||
LoadF lf;
|
LoadF lf;
|
||||||
int status; //, readstatus;
|
int status;
|
||||||
char buffer[MAX_PATH];
|
char buffer[MAX_PATH];
|
||||||
// int c;
|
|
||||||
int fnameindex = lua_gettop(L) + 1; /* index of filename on the stack */
|
int fnameindex = lua_gettop(L) + 1; /* index of filename on the stack */
|
||||||
lf.extraline = 0;
|
lf.extraline = 0;
|
||||||
// if (filename == NULL) {
|
lf.f = rb->open(filename, O_RDONLY);
|
||||||
// lua_pushliteral(L, "=stdin");
|
if(lf.f < 0) {
|
||||||
// lf.f = stdin;
|
/* Fallback */
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
lua_pushfstring(L, "@%s", filename);
|
|
||||||
lf.f = rb->open(filename, O_RDONLY);
|
|
||||||
if (lf.f < 0)
|
|
||||||
{
|
|
||||||
/* Fallback */
|
|
||||||
snprintf(buffer, sizeof(buffer), "%s/%s", curpath, filename);
|
|
||||||
lf.f = rb->open(buffer, O_RDONLY);
|
|
||||||
|
|
||||||
if(lf.f < 0)
|
lua_Debug ar;
|
||||||
{
|
if(lua_getstack(L, 1, &ar)) {
|
||||||
snprintf(buffer, sizeof(buffer), "%s/%s", VIEWERS_DIR, filename);
|
lua_getinfo(L, "S", &ar);
|
||||||
lf.f = rb->open(buffer, O_RDONLY);
|
|
||||||
|
|
||||||
if(lf.f < 0)
|
/* Try determining the base path of the current Lua chunk
|
||||||
return errfile(L, "open", fnameindex);
|
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);
|
||||||
}
|
}
|
||||||
// }
|
|
||||||
// c = getc(lf.f);
|
if(lf.f < 0) {
|
||||||
// if (c == '#') { /* Unix exec. file? */
|
snprintf(buffer, sizeof(buffer), "%s/%s", VIEWERS_DIR, filename);
|
||||||
// lf.extraline = 1;
|
lf.f = rb->open(buffer, O_RDONLY);
|
||||||
// while ((c = getc(lf.f)) != EOF && c != '\n') ; /* skip first line */
|
|
||||||
// if (c == '\n') c = getc(lf.f);
|
if(lf.f < 0)
|
||||||
// }
|
return errfile(L, "open", fnameindex);
|
||||||
// if (c == LUA_SIGNATURE[0]) { // && lf.f != stdin) { /* binary file? */
|
}
|
||||||
// rb->close(lf.f);
|
|
||||||
// lf.f = rb->open(filename, O_RDONLY); /* reopen in binary mode */
|
if(lf.f >= 0)
|
||||||
// if (lf.f < 0) return errfile(L, "reopen", fnameindex);
|
lua_pushfstring(L, "@%s", buffer);
|
||||||
/* skip eventual `#!...' */
|
}
|
||||||
// while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) ;
|
else
|
||||||
// lf.extraline = 0;
|
lua_pushfstring(L, "@%s", filename);
|
||||||
// }
|
|
||||||
// ungetc(c, lf.f);
|
|
||||||
status = lua_load(L, getF, &lf, lua_tostring(L, -1));
|
status = lua_load(L, getF, &lf, lua_tostring(L, -1));
|
||||||
// readstatus = ferror(lf.f);
|
|
||||||
//if (lf.f != stdin) rb->close(lf.f); /* close file (even in case of errors) */
|
|
||||||
rb->close(lf.f);
|
rb->close(lf.f);
|
||||||
// if (readstatus) {
|
|
||||||
// lua_settop(L, fnameindex); /* ignore results from `lua_load' */
|
|
||||||
// return errfile(L, "read", fnameindex);
|
|
||||||
// }
|
|
||||||
lua_remove(L, fnameindex);
|
lua_remove(L, fnameindex);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
@ -653,9 +655,10 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
|
||||||
|
|
||||||
|
|
||||||
static int panic (lua_State *L) {
|
static int panic (lua_State *L) {
|
||||||
(void)L; /* to avoid warnings */
|
|
||||||
DEBUGF("PANIC: unprotected error in call to Lua API (%s)\n",
|
DEBUGF("PANIC: unprotected error in call to Lua API (%s)\n",
|
||||||
lua_tostring(L, -1));
|
lua_tostring(L, -1));
|
||||||
|
rb->splashf(5 * HZ, "PANIC: unprotected error in call to Lua API (%s)",
|
||||||
|
lua_tostring(L, -1));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -251,6 +251,19 @@ RB_WRAP(get_action)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_TOUCHSCREEN
|
||||||
|
RB_WRAP(action_get_touchscreen_press)
|
||||||
|
{
|
||||||
|
short x, y;
|
||||||
|
int result = rb->action_get_touchscreen_press(&x, &y);
|
||||||
|
|
||||||
|
lua_pushinteger(L, result);
|
||||||
|
lua_pushinteger(L, x);
|
||||||
|
lua_pushinteger(L, y);
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
RB_WRAP(action_userabort)
|
RB_WRAP(action_userabort)
|
||||||
{
|
{
|
||||||
int timeout = luaL_checkint(L, 1);
|
int timeout = luaL_checkint(L, 1);
|
||||||
|
@ -261,10 +274,15 @@ RB_WRAP(action_userabort)
|
||||||
|
|
||||||
RB_WRAP(kbd_input)
|
RB_WRAP(kbd_input)
|
||||||
{
|
{
|
||||||
char* buffer = (char*)luaL_checkstring(L, 1);
|
luaL_Buffer b;
|
||||||
int buflen = luaL_checkint(L, 2);
|
luaL_buffinit(L, &b);
|
||||||
int result = rb->kbd_input(buffer, buflen);
|
|
||||||
lua_pushinteger(L, result);
|
char *buffer = luaL_prepbuffer(&b);
|
||||||
|
buffer[0] = '\0';
|
||||||
|
rb->kbd_input(buffer, LUAL_BUFFERSIZE);
|
||||||
|
luaL_addsize(&b, strlen(buffer));
|
||||||
|
|
||||||
|
luaL_pushresult(&b);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -467,6 +485,9 @@ static const luaL_Reg rocklib[] =
|
||||||
#endif
|
#endif
|
||||||
R(get_action),
|
R(get_action),
|
||||||
R(action_userabort),
|
R(action_userabort),
|
||||||
|
#ifdef HAVE_TOUCHSCREEN
|
||||||
|
R(action_get_touchscreen_press),
|
||||||
|
#endif
|
||||||
R(kbd_input),
|
R(kbd_input),
|
||||||
|
|
||||||
/* Hardware */
|
/* Hardware */
|
||||||
|
|
|
@ -46,23 +46,6 @@ static void rocklua_openlibs(lua_State *L) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char curpath[MAX_PATH];
|
|
||||||
static void fill_curpath(const char* filename)
|
|
||||||
{
|
|
||||||
char* pos = rb->strrchr(filename, '/');
|
|
||||||
|
|
||||||
if(pos != NULL)
|
|
||||||
{
|
|
||||||
int len = (int)(pos - filename);
|
|
||||||
|
|
||||||
if(len > 0)
|
|
||||||
memcpy(curpath, filename, len);
|
|
||||||
|
|
||||||
curpath[len] = '\0';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/***************** Plugin Entry Point *****************/
|
/***************** Plugin Entry Point *****************/
|
||||||
enum plugin_status plugin_start(const void* parameter)
|
enum plugin_status plugin_start(const void* parameter)
|
||||||
{
|
{
|
||||||
|
@ -79,7 +62,6 @@ enum plugin_status plugin_start(const void* parameter)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
filename = (char*) parameter;
|
filename = (char*) parameter;
|
||||||
fill_curpath(filename);
|
|
||||||
|
|
||||||
lua_State *L = luaL_newstate();
|
lua_State *L = luaL_newstate();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue