lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi,

On Mon, Jul 31, 2023 at 12:46 PM bil til <biltil52@gmail.com> wrote:
Am Mo., 31. Juli 2023 um 10:58 Uhr schrieb Bogdan Marinescu
<bogdan.marinescu@gmail.com>:
> I never thought about that, because I thought that internal alignment is preserved by default. Apparently things just worked, which admittedly is quite rare :)

If I want to load a binary Lua code from Flash-ROM, and I want to keep
all the Code in ROM, do you estimate that this could be done with
"minor changes" in lundump.c, e. g. mainly in the static function
LoadStringN of this c file? So then I would need a "pimped up" TString
object, which supports the possibility that this constant code string
is kept in Flash-ROM and TString mainly only saves the Flash ROM
pointer?

Or would such a modification be much more elaborate? (how many Lua
code line changes do you estimate? More "< 100" or more "> 1000" :) ?

Sorry for the late reply. To use binary Lua code directly from flash/ROM, the first thing that needs to happen is to make Lua aware that such a thing exists. There are a few ways to handle this. eLua's way is to use the regular file I/O operations that are already used in the Lua source code, but it adds a "get_file_address_in_memory" function that returns a pointer to the file data if that data exists in a contiguous memory area (which would somewhere in flash) or NULL if it doesn't. Of course this requires some other changes to the code. Also, this isn't necessarily the best way to do things, but it works well with eLua's ROM file system (basically a bunch of files dumped in a C array with some metadata that contains their names, sizes and so on). 
For TStrings, I ended up implementing a separate "rostring" type (I explained in a previous post how that works). That's not necessarily hard, but it can be tricky, especially since it requires changes to other parts of the code too (for example the garbage collector). I think I might have somewhere the "rostring" patch for Lua 5.3, I can try to locate it if you want (but keep in mind that it was tested only very briefly and never actually used).

Hope this helps,
Bogdan