[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: How should I set up C + Lua modules
- From: Peter Odding <peter@...>
- Date: Thu, 10 Feb 2011 22:55:04 +0100
My Lua/APR binding  includes lots of C source code plus a few 'sugar'
functions as you describe them. The easiest way I've found to combine
them is more or less as you envision it:
There's a Lua script which is loaded on require 'apr', this file is
named "apr.lua"  and is placed in one of the top level directories in
Lua's module search path. The first line of this script contains:
local apr = require 'apr.core'
-- .. and the script ends with ..
The binary module is called "core.so" ("core.dll" on Windows) and is
located in a subdirectory "apr" in one of the directories in Lua's
binary module search path. The loader function in the binary module 
is called "luaopen_apr_core".
The nice thing about this scheme is that your Lua script can remove some
functions from the module table created in C and save those functions in
local variables. Now your Lua functions can call the C functions to
perform low level tasks and the C functions don't have to be foolproof
because you'll be writing the code that calls them.
- Peter Odding