Commit graph

12 commits

Author SHA1 Message Date
William Wilgus
3e2b50ed3b lua events from rockbox
This library allows events to be subscribed / recieved within a lua script
most events in rb are synchronous so flags are set and later checked by a
secondary thread to make them (semi?) asynchronous.

There are a few caveats to be aware of:

FIRST, The main lua state is halted till the lua callback(s) are finished
 Yielding will not return control to your script from within a callback
 Also, subsequent callbacks may be delayed by the code in your lua callback
SECOND, You must store the value returned from the event_register function
 you might get away with it for a bit but gc will destroy your callback
 eventually if you do not store the event
THIRD, You only get one cb per event type
 ["action", "button", "custom", "playback", "timer"]
 (Re-registration of an event overwrites the previous one)

Usage:
 possible events =["action", "button", "custom", "playback", "timer"]

 local evX = rockev.register("event", cb_function, [timeout / flags])
  cb_function([id] [, data]) ... end

 rockev.suspend(["event"/nil][true/false]) passing nil affects all events
  stops event from executing, any but the last event before
  re-enabling will be lost, passing false, unregistering or re-registering
  an event will clear the suspend

 rockev.trigger("event", [true/false], [id])
  sets an event to triggered,
  NOTE!, CUSTOM_EVENT must be unset manually
  id is only passed to callback by custom and playback events

 rockev.unregister(evX)
  Use unregister(evX) to remove an event
  Unregistering is not necessary before script end, it will be
  cleaned up on script exit

Change-Id: Iea12a5cc0c0295b955dcc1cdf2eec835ca7e354d
2019-07-19 20:48:34 -05:00
William Wilgus
e36edaee55 Lua fix crash on arm devices
This is a seemingly random bug that only affects (as far as I can tell)
arm devices it isn't actually random as code changes cause it to
appear/disappear based on alignment

Change-Id: I4cbc4370677959319f8589fe454e854c45623468
2018-11-17 09:04:05 -05:00
William Wilgus
9b385f37ef Lua fix dir string constants and pcm_play_pause & pcm_set_frequency
String constants were already expanded in the first macro
pcm functions were looking for stack position #1 when they needed stack pos #2

Change-Id: I7b4fb90953ab2395b77cbd550fdd257fafca6aae
2018-11-01 18:18:46 -04:00
William Wilgus
eab73b3dee Lua replace fscanf
Rocklua was using the full fscanf implementation
to simply read %ld for the file:read("*n") function
wasting 1k on unneeded/unused functionality

Instead, I've implemented a filetol function to duplicate it
without the extra overhead using strtol which as an added bonus
ERANGE errors now resolve to LONG_MIN and LONGMAX instead of
integer overflow

filetol()
   reads long int from an open file, skips preceding
   whitespaces returns -1 if error, 1 on success.
   *num set to LONG_MAX or LONG_MIN on overflow.
   If number of digits is > than LUAI_MAXNUMBER2STR
   filepointer will continue till the next non digit
   but buffer will stop being filled with characters.
   Preceding zero is ignored.

Change-Id: Ia42d0f73c63a894625bca4581e9b7e1cc7387fd2
2018-10-29 23:22:35 -04:00
William Wilgus
07fed9053a lua optimize current_path function
frees up around 500 bytes by using the builtin string functionality

Change-Id: Icd4ec921d3fec339b8a4b7f80c9c63d51d4c101c
2018-10-15 18:24:10 +02:00
William Wilgus
e4b843335b lua rocklib cleanup
removes tslf allocations from do_menu and gui_syncyesno_run in favor of
lua_newuserdata

removes some luaL_opt functions in favor of equivalent lua_to functions

moves some definitions to the rocklib.h file

Change-Id: Iaacc3249b8f1af2c220ce59dead0050c66cb3b04
2018-10-08 23:15:16 +02:00
William Wilgus
733c20d5d3 lua move RLIMAGE to own file
Change-Id: Icd10e4c348deec7729d4a6e2bf1152e1dfc70243
2018-09-14 01:00:35 +02:00
Marcin Bukat
bfd0179042 Revert "Update lua plugin to 5.2.3"
FILE typedef to *void needs more work to not break sim and
application builds. I checked only a few random native builds
unfortunately. Sorry for inconvenience.
2014-04-02 20:46:06 +02:00
Richard Quirk
36378988ad Update lua plugin to 5.2.3
Prior to this patch the Lua plugin used version 5.1.4. This change
reduces the number of modifications in the Lua source using some new
defines and because the upstream source is now more flexible.

Unless otherwise stated, l*.[ch] files are taken unmodified from the
upstream lua-5.2.3.

fscanf.c:
file descriptors in rockbox are just ints, they are hidden behind a
void* now so liolib requires less modifications. fscanf is updated to
use void* too.

getc.c: this is a new file required for getc implementation in lauxlib.c

lauxlib.c: LoadF replaced FILE* with int, the rockbox file
descriptor int are cast to FILE* (actually void* due to typedef).
getc uses the PREFIX version. stdin is not used, as per 5.1.4.

lbaselib.c: now uses strspn in the number parsing. print uses DEBUGF now
rather than being commented out.

lbitlib.c: use the built-in version from 5.2.3 rather than Reuben
Thomas's external library. Backwards compatible and adds some new bit
operations.

ldo.c: the LUAI_THROW/TRY defines are now in the core lua code, so have
been removed from rockconf.h

liolib.c: here the implementation has changed to use the LStream from
the original source, and cast the FILE* pointers to int. This has
reduced the number of modifications from the upstream version.

llex.c: the only change from upstream is to remove the locale include.

lmathlib.c: updated from the 5.2.3 version and re-applied the changes
that were made vs 5.1.4 for random numbers and to remove unsupported
float functions.

loadlib.c: upstream version, with the 5.1.4 changes for missing
functions.

lobject.c: upstream version, with ctype.h added and sprintf changed to
snprintf.

loslib.c: upstream version with locale.h removed and 5.1.4 changes for
unsupportable functions.

lstrlib.c: sprintf changed to snprintf.

ltable.c: upstream with the hashnum function from 5.1.4 to avoid frexp
in luai_hashnum.

luaconf.h: updated to 5.2.3 version, restored relevant parts from the
original 5.1.4 configuration. The COMPAT defines that are no longer
available are not included.

lundump.c: VERSION macro conflicts with the core Rockbox equivalent.

rocklib.c: luaL_reg is no longer available, replaced by luaL_Reg
equivalent. Moved checkboolean/optboolean functions to this file and out
of core lua files. luaL_getn is no longer available, replaced by
luaL_rawlen. luaL_register is deprecated, use the newlib/setfuncs
replacements. rli_init has to be called before setting up the newlib to
avoid overwriting the rb table.

rocklib_aux.pl: use rli_checkboolean from rocklib.c.

rocklua.c: new default bits library used, update the library loading
code with idiomatic 5.2 code.

strcspn.c: no longer needed, but strspn.c is required for strspn in
lbaselib.c

Change-Id: I0c7945c755f79083afe98ec117e1e8cf13de2651
Reviewed-on: http://gerrit.rockbox.org/774
Tested: Richard Quirk <richard.quirk@gmail.com>
Reviewed-by: Marcin Bukat <marcin.bukat@gmail.com>
2014-04-02 20:31:54 +02:00
Maurus Cuelenaere
9bff845b49 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
2009-07-01 17:01:22 +00:00
Maurus Cuelenaere
9c3e679d18 Lua: add touchscreen_set_mode & current_path (+ some constants)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21165 a1c6a512-1295-4272-9138-f99709370657
2009-06-01 22:31:32 +00:00
Maurus Cuelenaere
cf87597226 Commit FS#9174: Lua scripting language by Dan Everton
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21020 a1c6a512-1295-4272-9138-f99709370657
2009-05-21 19:01:41 +00:00