Commit Graph

14 Commits

Author SHA1 Message Date
William Wilgus
8c36d8b131 lua Fix a few potential bugs
Change-Id: I0293371c58f1ca2d148b3b1e1f780cf76f312ef9
2021-08-13 22:44:45 -04:00
William Wilgus
dcff9b85a3 lua latebound function update
return the nextfunction and nil instead of pairs it allows a faster
return to lua rather than calling the lua function
pcall(fnpairs) from c and returning the result back
into lua to kick off the search
yeah, no clue why I didn't realize that before..

testing in x86 and ARM..
its more RAM efficient to do the initial creation
of the stack in lua code for the __pairs functon
its not faster but being that its a one time hit per
iter creation the reduced churn alone should be worth it
along with a reduced peak RAM usage

fix bug where a failed module can not be reloaded

optimize filetol

fix potential bug in splash scroller when no break character is found
Change-Id: I42c922e07039a19138b97c0d0e80cf3cf2426471
2021-05-19 23:28:35 +00:00
William Wilgus
45bd14b392 Lua Add Emergency Garbage Collector
Derivative of work by RobertGabrielJakabosky
 http://lua-users.org/wiki/EmergencyGarbageCollector

I've only implemented the not enough memory part and
 expanded this idea to adding a mechanism to signal
 the OOM condition of the plugin buffer which allows us to only
 grab the playback buffer after garbage collection fails
 (SO THE MUSIC KEEPS PLAYING AS LONG AS POSSIBLE)

Change-Id: I684fb98b540ffc01f7ba324ab5b761ceb59b9f9b
2019-07-28 15:17:48 +02:00
William Wilgus
a332924f68 lua late bound cfunction tables
We have quite a bit of ram tied up in lua with our c libraries
I was searching for a way to free up some of this when I came
across read only tables in e-lua but that involved a lot of patching
through the source

Instead I came up with this..
it frees about 15k ram without much slowdown in code execution
since after a function gets called it is automatically added to the table

If you have a performance issue you can call the bind method
to bind a specific function or the whole table in one shot

for instance rb table
rb("lcd_clear") -- binds/returns function rb.lcd_clear()
rb(nil) -- binds every function in rb table + removes latebind metatable ..

-- added pairs and ipairs code from lua 5.2
-- cleaned up code + made more seamless
  existing fields are now saved rather than overwritten when table is bound

Change-Id: I1c20e76b736c032dedc727d2e58928641e40191d
2019-07-11 00:09:54 -05:00
William Wilgus
c6fcb1cf45 lua inbinary strings
Allows saving of ram by reusing strings already stored in the binary
and storing a pointer instead of malloc and copy to get them inside
the lua state

Saves about 1.5K overall

Derivative of work by bogdanm
RAM optimizations: pseudo RO strings, functions in Flash
d54659b572

Change-Id: I21d6dcfa32523877efd9f70fb0f88f2a02872649
2019-07-11 00:31:41 +02:00
William Wilgus
b69faf0bcc lua update to 5.1.5
Modify Rocklua towards upstream 5.1.5

Clean up some of the Rocklua implementation

Change-Id: Iac722e827899cf84f5ca004ef7ae7ddce5f7fbbe
2018-11-11 19:42:30 -05: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
3ff84e5e4f Lua: add the package library
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21506 a1c6a512-1295-4272-9138-f99709370657
2009-06-25 13:26:05 +00:00
Maurus Cuelenaere
388e31cb96 Fix FS#10378: Lua crashes when loading non-existing files
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21488 a1c6a512-1295-4272-9138-f99709370657
2009-06-24 10:39:07 +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
aec37aa5fe * read_bmp_*(): add FORMAT_RETURN_SIZE
* Lua: add luaL_checkboolean() & luaL_optboolean()
* Lua: add read_bmp_file


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21074 a1c6a512-1295-4272-9138-f99709370657
2009-05-25 11:12:27 +00:00
Maurus Cuelenaere
0f7e4e36ae 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
2009-05-22 22:44:34 +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