lua-users home
lua-l archive

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


On Tue, Aug 16, 2005 at 02:51:53PM +0200, Wim Couwenberg wrote:

> > The way I do it is to have the Lua script load the C module and add to
> > it all the sugar that it chooses too. 

<snip>

> Yes, it can be done like this, but like I said, I don't view the Lua
> script part as a separate module (or the DLL if you reverse the roles
> of DLL and script).  The script is really private to the DLL and both
> communicate through private functions and tables that are unreachable
> from outside of the module.

Although it's a conceptually a little muddier, you achieve the same
result by having the Lua script load the C module and using local
variables in the Lua script.  Your DLL doesn't have to jump through
hoops to find the lua script, either.

For example,

  local loadlib = _G.loadlib
  -- the rest of your imports here

  local mypackage = module 'mypackage'

  local private = {}

  function private.foo(...) end
  function private.bar(...) end
  -- etc.  define private functions and variable types

  local c_part = assert(loadlib("mydll.dll", "mydll_init"))
  return c_part(mypackage,private)

Cheers!

-- 
Shannon Stewman         | Let us walk through the waning night,
Caught in a whirlpool,  | As dawn-rays tickle our toes, the dew soothes
A quartering act:       | Our blistered soles, and damp bones stir
Solitude or society?    | As crimson cracks under the blue-grey sky.