[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: How to add C functions to a Lua module within the require process?
- From: Jerome Vuarand <jerome.vuarand@...>
- Date: Thu, 3 Dec 2009 17:59:10 +0100
2009/12/3 Javier Guerra <firstname.lastname@example.org>:
> 2009/12/3 Ignacio Burgueño <email@example.com>:
>> So far, so good. The problem I have is that I need to add a C function to
>> Foo.Bar and I can't find a good way to do that.
> my first idea would be to put it in Foo, using a discouraging name
> (something like Foo.__to_be_defined__). in the Bar code you can use
> it, or maybe just give it a better name under Bar's namespace
Another solution is to create a third module called Foo.Bar.core,
implemented in C. Within Foo.Bar, you can then write :
local core = require(_NAME..".core")
for k,v in pairs(core) do _M[k] = v end
Thanks to the "all-in-one" loader, you can put Foo.Bar.core
(luaopen_Foo_Bar_core) in Foo.dll. The C code will be loaded in memory
with the Foo module, but it won't be loaded into the Lua interpreter
until you require Foo.Bar.core.