[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Execution of pre compiled lua code from memory mapped files
- From: Dirk Laurie <dirk.laurie@...>
- Date: Thu, 28 May 2015 10:56:34 +0200
2015-05-28 10:28 GMT+02:00 Hans Riekehof <Riekehof@schoeps.de>:
> But I still think that including memory mapping directly to the Lua language
> would be a nice thing. Not just for embedded systems.
Lua has it under the name "light userdata". You write a C procedure
that creates a void* in any way you please (malloc, mmap, whatever),
lua_pushlightuserdata it and return it to Lua. Make the procedure visible
to Lua via "require".
Lua can't see into the memory; all it can do is assign the pointer to a Lua
name and later pass it as a parameter to other C procedures you have
written that can derefence the pointer and operate on the contents.
If you want object-oriented access to light userdata, you will have
to use debug.setmetatable. Light userdata does not have subtyping,
so there is only one metatable for all.
The manual is quite terse on this topic. You should rather read about it
in "Programming in Lua" <www.lua.org/pil>.