Commit graph

190 commits

Author SHA1 Message Date
William Wilgus
df1b3c1d2c lua RockEv timing fixes
just a few tweaks to the RockEv backend to allow tighter event timing

originally there was a timeout where events would be consolidated
prior to running the event thread, this slowed the faster events
but it turns out this isn't really a big waster of time
The callback from C => lua is a far bigger bottleneck

Change-Id: Iffacbe49c4b83155099b1304590450f746576fa4
2020-06-23 11:17:17 +00:00
William Wilgus
e4ee5980c6 lua add _fullpath and argument parsing
WIP for passing arguments to lua scripts

args are recognized by adding ?arg to the end of the script path
The easiest way to do this currently is to use the function rb.restart_lua

local sfile = rawget(_G, "_fullpath") or ""
local sArgs = rawget(_G, "_arguments")

if not sArgs then
    rb.restart_lua(sfile .. "?my arguments")
else
    rb.splash(1000, sfile .. "?" .. sArgs)
end

I'd eventually like to figure out a sensible way to do this from a
shortcut / quick list

Change-Id: I2b60fe3b8f1d04b57361fe532510bd6afee59fbf
2020-06-01 13:23:38 -05:00
William Wilgus
f45db552f3 lua rockev rewrite
After a few issues with the timer code in the hosted players

I realized a few shortcomings in the original rockev code...
This rewrite gives thread_exit an explicit flag instead of 0
custom events now have a set-able timeout
previous lua hooks are restored
flags are stored in uint8_t

Change-Id: I9ca45246ac9233a2faa581e26a8cc5e5fb512e88
2019-11-15 14:28:03 +01:00
William Wilgus
7f1e6b4638 lua rockev cleanup
with the addition of suspending all events on thread start and exit
we don't really need to block on THREAD_QUIT in so many places

Removed suspend clearing on event unregister and updated comments

Change-Id: Id9c6a460def558c5331ee292035691a9f82b2c43
2019-10-07 22:07:22 -05:00
William Wilgus
19084181a1 lua rockev fix possible race on thread exit
report of call after free on event thread on Agptek Rocker
I'm guessing its a race condition between the thread and the timer
but can't say for sure without some more testing

Change-Id: If11bd718b3cfa81ea13fff378df56d12afa17a7f
2019-10-08 01:09:52 +02:00
William Wilgus
01cccaf2d2 lua move strip_extension and create_numbered_filename out of main binary
rb.strip_extension and rb.create_numbered_filename
have been moved to include_lua/files.lua
to use simply add require('files') to your script

Change-Id: I95af7b312c8614cb10da4b71b22714b3e282e08a
2019-09-28 03:15:15 +02:00
William Wilgus
4fb783582f lua rocklib_aux.pl support for enums
everything that would have been added has already been added or
needs more supporting functions so they've been excluded for the time being

Change-Id: I4ae4753c543287934702a3bd2eeccce5b032235d
2019-09-27 11:11:34 -05:00
William Wilgus
bad739c0d8 Fix red lua remove and consolidate some rb plugin functions
I'll revisit adding enums once I research it a bit more

Change-Id: If10c445cf770e5b90defc543f08d8de0817b2f3d
2019-09-27 00:17:33 -05:00
William Wilgus
de06a06351 lua remove and consolidate some rb plugin functions
removes some usless / duplicated functions
removes atoi - lua tonumber() does this for you
removes strlen - lua string.len does this for you
removes system_memory_guard - if a device that actually implements
              system_memory_guard needs it we can add it back conditionally

consolidates talk_number and talk_spell (on backend)
consolidates talk_shutup and talk_force_shutup talk_shutup(bForce)

Change-Id: Id132642f087975a7c132e99a668a41c977942b81
2019-09-26 23:45:38 -05:00
William Wilgus
d0883d747a lua give luadir the ability to return table of attributes
for fname, isdir, attrib in luadir.dir(scrpath, true) do

passing true for the second argument returns table of
file/dir attributes in attrib

Change-Id: I7c999e2fc5dac95b8ccbe169f2119c31b63f6a41
2019-09-18 21:20:42 -05:00
William Wilgus
13245ebf76 lua add menu callback
forum user fprockboxer asked for a way to detect long presses within the
do_menu routine this adds that functionality

result = rb.do_menu("Title",t_items, start, menu_callback)

function menu_callback(action)
    ...
    return action
end

Change-Id: I110c590095a743a57d0a7d45b24309899a4629cf
2019-09-14 04:48:04 -05:00
William Wilgus
f9225da811 Fix red Lua extend error splash timeout and stop cutting off info
Change-Id: Icd6fe0fa1088ab59b8214f7c860f262ce67fe205
2019-09-06 21:13:16 -05:00
William Wilgus
bbd4a6cb91 Lua extend error splash timeout and stop cutting off info
Change-Id: Ia1a9e39b9f203002cbbea85ef965e66c334b83fc
2019-09-06 20:19:42 -05:00
William Wilgus
267d04d2bd Lua add metadata and settings reading helper module
Adds example scripts for reading track metadata + dumping albumart
and rockbox settings

settings are now stored as a table of strings rather than a table of tables
as it saves ~15 kb of ram without adding much complexity

Change-Id: I611c312b2a60ab96e595e4710b17aedbd6c0689b
2019-09-07 03:10:59 +02:00
William Wilgus
c251d1879f lua fix mem_read_write, strtol
back when I wrote this I was running the sim on a 32 bit machine
I didn't catch the hardcoded LONG_MAX reference or the fact that
lua_tointeger maxes ot at 32 bits

on 64 bit machines strtol caused all kinds of issues especially since
it returned the real LONG_MIN/MAX values

Change-Id: I3571ebbd9df333f7cbf4077562412c27429bfadc
2019-08-28 00:56:08 -05:00
William Wilgus
b99d4d7fa9 lua optimize poly_draw add draw_number, poly_points modules
Change-Id: Id36e765f18234f5a4f3092d090c0adffa3da1612
2019-08-26 22:17:33 -05:00
William Wilgus
ecfb4590ad lua fix polydraw missing functions
Change-Id: I9e2537e4839e2b4f9beddbc887610213ed954a87
2019-08-20 01:58:16 -05:00
William Wilgus
3d06d35bf6 lua rock events crash on error in main state
on errors thread stack overflows
yielding before thread_exit() is a bad idea apparently

Change-Id: Iac45d4321fac496738384fdbbeb480356ef2a1bb
2019-08-12 07:28:24 +02:00
Solomon Peachy
a430e275dd Fix lua compile error on most targets, introduced in 8d77ec8
Change-Id: I217f78a9e348a18552563c6c3b235c9aed956f54
2019-08-08 15:09:04 +02:00
William Wilgus
8d77ec88a5 lua LCD fix
forgot to set new size after realloc

forgot to set sizelineinfo to 0 after free

Change-Id: Iaf7533aafaba1e2abf9599c9e1d0b75d913a8c36
2019-08-08 07:36:04 -05:00
William Wilgus
d61ea6c5ee lua LCD (Lua Compact Debug) patch
LCD developed 9/2015 by Terry Ellison

 We've already discarded the ldebug module from lua
 it only makes sense to discard the debug info as well
 adds 1.5 K to the binary
 saves 8 Kb on the base state
 once scripts start getting called i've seen 10-50Kb savings but it all depends on
 what exactly you are running

Change-Id: Ibb74f344df1c4c96380ec6c98b010a810e9ae9cc
2019-08-08 07:11:30 +02:00
William Wilgus
951a614852 lua fix lua_close on os.exit(0)
Change-Id: Ib225ecf9ea64c95e438c4114b23239c118ab19a2
2019-08-05 21:25:01 -05:00
William Wilgus
1b41e6ec43 lua fix crashes EGC failure to lock stack in concat
Change-Id: I980637b1d8aa91d7ac0ed71fd0e7d21bda7876c4
2019-08-05 21:20:30 -05:00
William Wilgus
d1f349bf77 lua optimize print include, fix draw_poly
Change-Id: Ibb530cfa63681727be518173404952e897c9d297
2019-08-04 17:54:03 +02:00
William Wilgus
f85df30e3e lua add rlimg.lua example script split large includes to separate files
Change-Id: I67cac5bc4ce5525ab30abf9443f6cc1a33190512
2019-08-04 16:57:02 +02:00
William Wilgus
138a4f9d3d lua rocklib_img optimize functions with multiple checkint calls
Uses int arrays and calls luaL_checkint in a loop

Change-Id: Ib73dab886f018c787bd995f64d990981d194069f
2019-07-29 05:54:27 -05:00
William Wilgus
90118f14cf lua add demo scripts, atexit handler, gui_scrollbar_draw
Change-Id: Ie8794e8a487f73952dae43e036787b6972fdbbee
2019-07-29 02:51:29 -05:00
Franklin Wei
8379b230f6 lua: wrap thread_set_priority with #ifdef HAVE_PRIORITY_SCHEDULING
Should fix a compile-time error on simulator.

Change-Id: I5962479579350ebffe6dcce4f65a629b108ff936
2019-07-29 00:50:11 +02: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
ddf612c84b lua remove unneeded plugin functions
Change-Id: I04bc38d03b7f0ca65a815685eb6ab0f5ff825c45
2019-07-28 07:29:10 -05:00
William Wilgus
6e32e06498 lua add sound_current, consolidate sound_ functions
add defines for sound functions
 SOUND_VOLUME, SOUND_BALANCE, SOUND_CHANNELS, SOUND_STEREO_WIDTH ...
 defines depend on target
 require "sound_defines" to add them to rb.sound_settings[]

consolidates:
 sound_set, sound_current, sound_default, sound_min, sound_max,
 sound_unit, sound_pitch, sound_val2phys to a single function

 rb.sound("name", setting, [value])

 require "sound.lua" for old functionality

Change-Id: Ice695218aa433f4fcbb48fbd6b8a9bf29c994110
2019-07-25 10:17:40 -05:00
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
8bd992c503 lua disable bytecode dump & undump functions
Adds a flag to remove the ability to dump and load lua bytecode

saves 6+kb

Change-Id: I080323df7f03f752e0a10928e22a7ce3190a9633
2019-07-18 14:56:00 -05:00
William Wilgus
d5908f520e Fix Red lua move constants out of binary image
didn't consider sims might have reserved enums

Change-Id: Ic404972f0836bc81ba149f4ecdd3ec61bd8bd4b3
2019-07-18 10:53:34 -05:00
William Wilgus
c9aeb4284e lua move constants out of binary image
Rockbox constants are auto generated by a perl script like the majority
 of the plugin functions.

Constants are contained in rb_defines.lua, if the file exists it is auto loaded
 by the lua state for backwards compatibility

Frees ~1k

Change-Id: I237700576c748f468249e501c839d89effca3f39
2019-07-18 08:42:00 -05:00
William Wilgus
47639fb9ac lua alphabetically sort perl generated rocklib_aux functions
Change-Id: I6566c19a0fee630a5e250c1244159d5b488b57ff
2019-07-17 10:22:21 -05:00
William Wilgus
fc25562842 lua close state on os.exit
Change-Id: I376fad0f92f1155698740e1b8599a3385998575c
2019-07-13 07:46:32 -05:00
William Wilgus
ee58f2601c lua reduce heap allocated buffer sizes, organize luaconf.h
Change-Id: Ib9e568ea73a01474facd57cc155e62fa3dc093f7
2019-07-11 11:59:43 -05: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
c0dbfc8130 lua add track length & elapsed to rb.audio()
track elapsed is needed to use fast-forward and rewind effectively
track length might as well be added too..

Change-Id: I906c92eb5260164c6177d8c0a8ff879b1fad7898
2019-07-10 05:07:25 +02:00
William Wilgus
c7f26de2bf lua remove error messages for pre-compiled chunks
We don't have the functionality in the viewer to run pre-compiled chunks
plus if anyone ever wants to add it its easy enough to remove the define
frees 3K

Change-Id: I8d2086e04b51e3ce147ab8741a7d354cb9bf1ade
2019-07-09 01:03:58 +02:00
William Wilgus
a71af1778d Fix lua helpers -- supress line markers in preproc source generation scripts
In newer builds line markers prevent lua helper scripts
from grabbing some inputs especially _bool

This patch adds the -P switch
  Inhibit generation of linemarkers in the output from the preprocessor.
  This might be useful when running the preprocessor on something that
  is not C code, and will be sent to a program which might be confused
  by the linemarkers.

Change-Id: I66c3b099729f6651300f9fcf4670533a20cc90c1
2018-12-24 21:37:06 +01:00
William Wilgus
28f91ff3dc Lua Fix settings_helper for the gigaBeastS
the gigabeatS has an embedded struct that needs to be parsed

Change-Id: I88c9101afaaa95182f37ade1410cccb4fb768e33
2018-12-17 09:41:15 -06:00
William Wilgus
9d66b5459e Lua add read/write access to global_status, global_settings, audio_current_track
moved items to rb.system
added read access to audio_current_track and audio_next_track

Change-Id: Ia055b8cb3848e540067818f596ffd1058da057fb
2018-12-16 13:33:18 -06:00
William Wilgus
9ed486bdc7 lua add LCD_DEFAULT_FG, fix 2-bit screen fg/bg inversion
Change-Id: Ibe2bc6602ff27524a3b96d9523780acbfbf03c76
2018-11-24 16:40:23 -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
03718bdb76 Lua fix reader bug in lzio
When loading a file, Lua may call the reader function again after it
returned end of input

https://www.lua.org/bugs.html#5.1.5-2

Change-Id: Ic2f4d727705a0b8f48ce792f6a9f7af25a503037
2018-11-15 11:20:54 +01: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
William Wilgus
d9f9def505 Lua fix failure to read lines longer than LUAL_BUFFERSIZE
Readline didn't handle lines longer than LUAL_BUFFERSIZE it now
reads these in chunks.

Change-Id: Iffe12447e5441ff6b479ce3de1d36df64c276183
2018-11-02 23:18:30 -04:00