Re: How should I set up C + Lua modules
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: How should I set up C + Lua modules
 
- From: Peter Odding <peter@...>
 
- Date: 2011年2月10日 22:55:04 +0100
 
Hi Michael,
My Lua/APR binding [1] 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" [2] 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 ..
	return apr
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 [3] 
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
[1] http://peterodding.com/code/lua/apr/
[2] http://github.com/xolox/lua-apr/blob/master/src/apr.lua
[3] http://github.com/xolox/lua-apr/blob/master/src/lua_apr.c