lua-users home
lua-l archive

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


On Tue, Apr 24, 2012 at 9:31 PM, James Urso <JUrso@walchem.com> wrote:
> (...)
>
> int luaopen_testHarness(lua_State *L)
> {
>   luaL_newlib (L, testHarness);   /* register C functions with Lua */
>   return 1;
> }
>
> (...)
>
> Is there something I can do so that I don’t need to have the “th.” In front
> of the call to the buildMessage function in the C library?

To populate the global table with your module's functions instead of
creating a new table and populating that, look into using
luaL_setfuncs() directly in your luaopen function instead of
luaL_newlib(). Something like this (untested):


int luaopen_testHarness(lua_State *L)
{
  // get global table onto the stack
  lua_pushglobaltable(L);
  // populate the table on top of the stack with module functions
  luaL_setfuncs(L, testHarness, 0);
  // since we don't have a module table, don't return anything
  // require() will return true instead
  return 0;
}


-Duncan