lua-users home
lua-l archive

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


this is not exactly what i mean. Its not about interacting with C/C++ because this is already available through the API.
If I have compiled C/C++ code I think its already the case, that the ram consumption is not that high if you register this in a lua state.

My idea is to have this for pre compiled lua code because I want to write a lot of code in Lua and not in C/C++.


-----Ursprüngliche Nachricht-----
Von: [] Im Auftrag von Dirk Laurie
Gesendet: Donnerstag, 28. Mai 2015 10:57
An: Lua mailing list
Betreff: Re: Execution of pre compiled lua code from memory mapped files

2015-05-28 10:28 GMT+02:00 Hans Riekehof <>:

> 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" <>.