lua-users home
lua-l archive

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


> Date: Tue, 08 Apr 2014 05:42:14 +0000
> From: Thomas Jericke <tjericke@indel.ch>
> Subject: Re: mathlib
> 
> On 04/07/2014 10:06 AM, John Hind wrote:
> > I do not understand the mindset that assumes everything in the Lua
> > Reference Manual has to be implemented in 'C'. Why cannot some of the
> > standard libraries be implemented in Lua?
> 
> Because there is no standard way for Lua to find and load Lua files.
> For an embedded system without file system this is a problem. The
> standard libraries provided in Lua would have to be defined within C
> strings to be able to be statically bound to the program.
> 
Lua actually makes it very easy to write loaders for getting scripts from
sources other than the filesystem. See my
https://github.com/JohnHind/Winsh.lua. This can load scripts and Lua
libraries from Win32 resources embedded in the exe file along with the the
Lua core and parser. This is Windows specific, but a proof of concept.
Equally it could load from an address in EPROM memory or any other storage
scheme. And what is wrong with scripts in 'C' strings or bytecode in
initialised byte arrays?

Winsh.lua also demonstrates composite libraries: I have re-implemented the
'table' library starting with 'unpack' and 'sort' implemented in 'C' and
then passing over to Lua to add the remaining methods.

One criticism I'd make of the current implementation is the way the 'C'
libraries sometimes bypass the 'C' API and access Lua core internals
directly. Whether the libraries are implemented in 'C' or Lua, I think it
would be useful discipline to de-privilege them so they work through the
API, extended as necessary.