shared libraries - Where and when load a library in luajit ffi -
i making wrapper between c++ engine , lua, i'm using luajit , because of i'm using ffi "wrapper" between these two, since engine has , different parts thinking nice divide them in files , requiring them, however, after reading bit luajit found external libraries have load library, came this: when , should load library? in "glue" code (the 1 wich unifies modules)?, in everyone?, or better keep single file? also, deciding how slow loading library?
you can create 'core' module loads 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 create module each of engine parts: engine/graphics.lua
local ffi = require'ffi' -- still need load ffi here. local c = require'engine.core' -- load other dependent parts. -- if module uses types other parts of engine -- defined/loaded here before call ffi.cdef below. require'engine.types' ffi.cdef[[ /* define function/types part of engine here. */ ]] local _m = {} -- add glue functions _m module. function _m.glue_function() return c.engine_function() end return _m
the code in 'engine.core' module executed once. biggest issue separating engine parts handle cross type dependencies. solve add 'typedef struct name name;' 'engine.core' module types used in multiple parts.
Comments
Post a Comment