You can create a 'core' module that loads the library: engine/core.lua
local ffi = require'ffi'
local C = ffi.load('engine') -- loads .so/.dll
ffi.cdef[[
/* put common function/type definitions here. */
]]
-- return native module handle
return C
Then you would create a module for each of the engine parts: engine/graphics.lua
local ffi = require'ffi' -- still need to load ffi here.
local C = require'engine.core'
-- load other dependent parts.
-- If this module uses types from other parts of the engine they most
-- be defined/loaded here before the call to the ffi.cdef below.
require'engine.types'
ffi.cdef[[
/* define function/types for this part of the engine here. */
]]
local _M = {}
-- Add glue functions to _M module.
function _M.glue_function()
return C.engine_function()
end
return _M
The code in the 'engine.core' module will only be executed once. The biggest issue with separating the engine into parts will be to handle cross type dependencies. To solve this add 'typedef struct name name;' to the 'engine.core' module for types that are used in multiple parts.