lua-users home
lua-l archive

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

On 02/10/2011 02:13 PM, Henderson, Michael D wrote:
Hi, I'm working with Lua 5.1.4. I have question on modules that have both C and Lua funtions.

I have a vendor library that I've written a C-wrapper for. I'm trying to make that wrapper work like a module from PILv2. The library is libihcfg and has a function luaopen_ihcfg.

I also have some Lua functions that I would like to include in the module. They're all sugar to help things like initialization and lookups. They look like

   function ihcfg.setVectors(o)
     -- stuff

How should I set things up so that they're included with the require? I don't see any easy way to combine the chunk of functions with the C library. There's a paragraph in the PILv2 on p145 that mentions modules with C and Lua functions, but no details/

Should I just call this script "ihcfg.lua" and put it in the path so that require finds it and have the script call something like

   local clib = require "Cihcfg"

And copy the clib functions into the ihcfg table?

Assuming, of course, that I rename libihcfg to libCihcfg?

You should check out "Writing C/C++ Modules for Lua" by Ralph Steggink and Wim Couwenberg in Lua Gems. Its an excellent write up and approach to what you are trying to do.