summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/plugin.c4
-rw-r--r--apps/plugin.h6
-rwxr-xr-xapps/plugins/lua/action_helper.pl31
-rw-r--r--apps/plugins/lua/lauxlib.c95
-rw-r--r--apps/plugins/lua/rocklib.c29
-rw-r--r--apps/plugins/lua/rocklua.c18
6 files changed, 107 insertions, 76 deletions
diff --git a/apps/plugin.c b/apps/plugin.c
index f03b9337f9..05a27ea591 100644
--- a/apps/plugin.c
+++ b/apps/plugin.c
@@ -644,6 +644,10 @@ static const struct plugin_api rockbox_api = {
644 appsversion, 644 appsversion,
645 /* new stuff at the end, sort into place next time 645 /* new stuff at the end, sort into place next time
646 the API gets incompatible */ 646 the API gets incompatible */
647
648#ifdef HAVE_TOUCHSCREEN
649 action_get_touchscreen_press,
650#endif
647}; 651};
648 652
649int plugin_load(const char* plugin, const void* parameter) 653int plugin_load(const char* plugin, const void* parameter)
diff --git a/apps/plugin.h b/apps/plugin.h
index 5eb4b88f28..8ec0f19572 100644
--- a/apps/plugin.h
+++ b/apps/plugin.h
@@ -128,7 +128,7 @@ void* plugin_get_buffer(size_t *buffer_size);
128#define PLUGIN_MAGIC 0x526F634B /* RocK */ 128#define PLUGIN_MAGIC 0x526F634B /* RocK */
129 129
130/* increase this every time the api struct changes */ 130/* increase this every time the api struct changes */
131#define PLUGIN_API_VERSION 151 131#define PLUGIN_API_VERSION 152
132 132
133/* update this to latest version if a change to the api struct breaks 133/* update this to latest version if a change to the api struct breaks
134 backwards compatibility (and please take the opportunity to sort in any 134 backwards compatibility (and please take the opportunity to sort in any
@@ -806,6 +806,10 @@ struct plugin_api {
806 const char *appsversion; 806 const char *appsversion;
807 /* new stuff at the end, sort into place next time 807 /* new stuff at the end, sort into place next time
808 the API gets incompatible */ 808 the API gets incompatible */
809
810#ifdef HAVE_TOUCHSCREEN
811 int (*action_get_touchscreen_press)(short *x, short *y);
812#endif
809}; 813};
810 814
811/* plugin header */ 815/* plugin header */
diff --git a/apps/plugins/lua/action_helper.pl b/apps/plugins/lua/action_helper.pl
index 8460b6cb2a..f1a1e12d60 100755
--- a/apps/plugins/lua/action_helper.pl
+++ b/apps/plugins/lua/action_helper.pl
@@ -22,21 +22,38 @@ $input = $ARGV[0] . "/../../action.h";
22 22
23open(ACTION, "<$input") or die "Can't open $input!"; 23open(ACTION, "<$input") or die "Can't open $input!";
24 24
25print "-- Don't change this file!\n";
26print "-- It is automatically generated of action.h\n";
27print "rb.actions = {\n";
28
29$i = 0; 25$i = 0;
26$j = 0;
30while(my $line = <ACTION>) 27while(my $line = <ACTION>)
31{ 28{
32 chomp($line); 29 chomp($line);
33 if($line =~ /^\s*(ACTION_[^\s]+)(\s*=.*)?,$/) 30 if($line =~ /^\s*(ACTION_[^\s]+)(\s*=.*)?,\s*$/)
34 { 31 {
35 printf "\t%s = %d,\n", $1, $i; 32 $actions[$i] = sprintf("\t%s = %d,\n", $1, $i);
36 $i++; 33 $i++;
37 } 34 }
35 elsif($line =~ /^\s*(CONTEXT_[^\s]+)(\s*=.*)?,\s*$/)
36 {
37 $contexts[$j] = sprintf("\t%s = %d,\n", $1, $j);
38 $j++;
39 }
38} 40}
39 41
42close(ACTION);
43
44print "-- Don't change this file!\n";
45printf "-- It is automatically generated of action.h %s\n", '$Revision';
46
47print "rb.actions = {\n";
48foreach $action(@actions)
49{
50 print $action;
51}
40print "}\n"; 52print "}\n";
41 53
42close(ACTION); 54print "rb.contexts = {\n";
55foreach $context(@contexts)
56{
57 print $context;
58}
59print "}\n";
diff --git a/apps/plugins/lua/lauxlib.c b/apps/plugins/lua/lauxlib.c
index a755266bde..88abc3cde0 100644
--- a/apps/plugins/lua/lauxlib.c
+++ b/apps/plugins/lua/lauxlib.c
@@ -547,60 +547,62 @@ static int errfile (lua_State *L, const char *what, int fnameindex) {
547 return LUA_ERRFILE; 547 return LUA_ERRFILE;
548} 548}
549 549
550static void make_path(char* dest, size_t dest_size, char* curfile, char* newfile)
551{
552 char* pos = rb->strrchr(curfile, '/');
553 if(pos != NULL)
554 {
555 unsigned int len = (unsigned int)(pos - curfile);
556 len = len + 1 > dest_size ? dest_size - 1 : len;
557
558 if(len > 0)
559 memcpy(dest, curfile, len);
560
561 dest[len] = '/';
562 dest[len+1] = '\0';
563 }
564 else
565 dest[0] = '\0';
566
567 strncat(dest, newfile, dest_size - strlen(dest));
568}
550 569
551LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) { 570LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) {
552 LoadF lf; 571 LoadF lf;
553 int status; //, readstatus; 572 int status;
554 char buffer[MAX_PATH]; 573 char buffer[MAX_PATH];
555// int c;
556 int fnameindex = lua_gettop(L) + 1; /* index of filename on the stack */ 574 int fnameindex = lua_gettop(L) + 1; /* index of filename on the stack */
557 lf.extraline = 0; 575 lf.extraline = 0;
558// if (filename == NULL) { 576 lf.f = rb->open(filename, O_RDONLY);
559// lua_pushliteral(L, "=stdin"); 577 if(lf.f < 0) {
560// lf.f = stdin; 578 /* Fallback */
561// } 579
562// else { 580 lua_Debug ar;
563 lua_pushfstring(L, "@%s", filename); 581 if(lua_getstack(L, 1, &ar)) {
564 lf.f = rb->open(filename, O_RDONLY); 582 lua_getinfo(L, "S", &ar);
565 if (lf.f < 0) 583
566 { 584 /* Try determining the base path of the current Lua chunk
567 /* Fallback */ 585 and prepend it to filename in buffer. */
568 snprintf(buffer, sizeof(buffer), "%s/%s", curpath, filename); 586 make_path(buffer, sizeof(buffer), (char*)&ar.source[1], (char*)filename);
569 lf.f = rb->open(buffer, O_RDONLY); 587 lf.f = rb->open(buffer, O_RDONLY);
570
571 if(lf.f < 0)
572 {
573 snprintf(buffer, sizeof(buffer), "%s/%s", VIEWERS_DIR, filename);
574 lf.f = rb->open(buffer, O_RDONLY);
575
576 if(lf.f < 0)
577 return errfile(L, "open", fnameindex);
578 }
579 } 588 }
580// } 589
581// c = getc(lf.f); 590 if(lf.f < 0) {
582// if (c == '#') { /* Unix exec. file? */ 591 snprintf(buffer, sizeof(buffer), "%s/%s", VIEWERS_DIR, filename);
583// lf.extraline = 1; 592 lf.f = rb->open(buffer, O_RDONLY);
584// while ((c = getc(lf.f)) != EOF && c != '\n') ; /* skip first line */ 593
585// if (c == '\n') c = getc(lf.f); 594 if(lf.f < 0)
586// } 595 return errfile(L, "open", fnameindex);
587// if (c == LUA_SIGNATURE[0]) { // && lf.f != stdin) { /* binary file? */ 596 }
588// rb->close(lf.f); 597
589// lf.f = rb->open(filename, O_RDONLY); /* reopen in binary mode */ 598 if(lf.f >= 0)
590// if (lf.f < 0) return errfile(L, "reopen", fnameindex); 599 lua_pushfstring(L, "@%s", buffer);
591 /* skip eventual `#!...' */ 600 }
592// while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) ; 601 else
593// lf.extraline = 0; 602 lua_pushfstring(L, "@%s", filename);
594// } 603
595// ungetc(c, lf.f);
596 status = lua_load(L, getF, &lf, lua_tostring(L, -1)); 604 status = lua_load(L, getF, &lf, lua_tostring(L, -1));
597// readstatus = ferror(lf.f);
598 //if (lf.f != stdin) rb->close(lf.f); /* close file (even in case of errors) */
599 rb->close(lf.f); 605 rb->close(lf.f);
600// if (readstatus) {
601// lua_settop(L, fnameindex); /* ignore results from `lua_load' */
602// return errfile(L, "read", fnameindex);
603// }
604 lua_remove(L, fnameindex); 606 lua_remove(L, fnameindex);
605 return status; 607 return status;
606} 608}
@@ -653,9 +655,10 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
653 655
654 656
655static int panic (lua_State *L) { 657static int panic (lua_State *L) {
656 (void)L; /* to avoid warnings */
657 DEBUGF("PANIC: unprotected error in call to Lua API (%s)\n", 658 DEBUGF("PANIC: unprotected error in call to Lua API (%s)\n",
658 lua_tostring(L, -1)); 659 lua_tostring(L, -1));
660 rb->splashf(5 * HZ, "PANIC: unprotected error in call to Lua API (%s)",
661 lua_tostring(L, -1));
659 662
660 return 0; 663 return 0;
661} 664}
diff --git a/apps/plugins/lua/rocklib.c b/apps/plugins/lua/rocklib.c
index 99bc44c9a4..c99400c938 100644
--- a/apps/plugins/lua/rocklib.c
+++ b/apps/plugins/lua/rocklib.c
@@ -251,6 +251,19 @@ RB_WRAP(get_action)
251 return 1; 251 return 1;
252} 252}
253 253
254#ifdef HAVE_TOUCHSCREEN
255RB_WRAP(action_get_touchscreen_press)
256{
257 short x, y;
258 int result = rb->action_get_touchscreen_press(&x, &y);
259
260 lua_pushinteger(L, result);
261 lua_pushinteger(L, x);
262 lua_pushinteger(L, y);
263 return 3;
264}
265#endif
266
254RB_WRAP(action_userabort) 267RB_WRAP(action_userabort)
255{ 268{
256 int timeout = luaL_checkint(L, 1); 269 int timeout = luaL_checkint(L, 1);
@@ -261,10 +274,15 @@ RB_WRAP(action_userabort)
261 274
262RB_WRAP(kbd_input) 275RB_WRAP(kbd_input)
263{ 276{
264 char* buffer = (char*)luaL_checkstring(L, 1); 277 luaL_Buffer b;
265 int buflen = luaL_checkint(L, 2); 278 luaL_buffinit(L, &b);
266 int result = rb->kbd_input(buffer, buflen); 279
267 lua_pushinteger(L, result); 280 char *buffer = luaL_prepbuffer(&b);
281 buffer[0] = '\0';
282 rb->kbd_input(buffer, LUAL_BUFFERSIZE);
283 luaL_addsize(&b, strlen(buffer));
284
285 luaL_pushresult(&b);
268 return 1; 286 return 1;
269} 287}
270 288
@@ -467,6 +485,9 @@ static const luaL_Reg rocklib[] =
467#endif 485#endif
468 R(get_action), 486 R(get_action),
469 R(action_userabort), 487 R(action_userabort),
488#ifdef HAVE_TOUCHSCREEN
489 R(action_get_touchscreen_press),
490#endif
470 R(kbd_input), 491 R(kbd_input),
471 492
472 /* Hardware */ 493 /* Hardware */
diff --git a/apps/plugins/lua/rocklua.c b/apps/plugins/lua/rocklua.c
index e72591445f..fcc8a3f9c8 100644
--- a/apps/plugins/lua/rocklua.c
+++ b/apps/plugins/lua/rocklua.c
@@ -46,23 +46,6 @@ static void rocklua_openlibs(lua_State *L) {
46 } 46 }
47} 47}
48 48
49char curpath[MAX_PATH];
50static void fill_curpath(const char* filename)
51{
52 char* pos = rb->strrchr(filename, '/');
53
54 if(pos != NULL)
55 {
56 int len = (int)(pos - filename);
57
58 if(len > 0)
59 memcpy(curpath, filename, len);
60
61 curpath[len] = '\0';
62 }
63}
64
65
66/***************** Plugin Entry Point *****************/ 49/***************** Plugin Entry Point *****************/
67enum plugin_status plugin_start(const void* parameter) 50enum plugin_status plugin_start(const void* parameter)
68{ 51{
@@ -79,7 +62,6 @@ enum plugin_status plugin_start(const void* parameter)
79 else 62 else
80 { 63 {
81 filename = (char*) parameter; 64 filename = (char*) parameter;
82 fill_curpath(filename);
83 65
84 lua_State *L = luaL_newstate(); 66 lua_State *L = luaL_newstate();
85 67