[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Calling module from a C function
- From: "Jerome Vuarand" <jerome.vuarand@...>
- Date: Wed, 25 Apr 2007 10:29:35 -0400
Luis Carvalho wrote:
> On Wed, Apr 25, 2007 at 01:07:02AM -0400, Jérôme VUARAND wrote:
>> I'm writing a binary module, and I'd like it to integrate gracefully
>> into the module system. So I tried to call the "module" Lua function
>> from my luaopen_module C function. I used the code below. I first
>> call "module" with the module name and package.seeall as parameters,
>> and then I put my functions in LUA_ENVIRONINDEX (which module is
>> supposed to have replaced with the module table).
>>
>> Unfortunately, it doesn't seem to work. After loading the module,
>> module.new is nil. So is "module" supposed to work for C modules, and
>> if so how can I use it ?
>
> It should work fine with C modules. This worked for me:
>
> [...]
>
> $ lua
> Lua 5.1.1 Copyright (C) 1994-2006 Lua.org, PUC-Rio
>> require"lmodule"
>> = package.loaded.lmodule
> table: 0x3078e0
>> table.foreach(lmodule, print)
> new function: 0x307570
> _M table: 0x3078e0
> _NAME lmodule
> _PACKAGE
>> = lmodule.new()
> it works!
Thanks or the help. I'll try your code as soon I get home :-)