lua-users home
lua-l archive

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


> but I want to make sure I'm not overlooking a superior solution.

I don't see a better solution because the rest of the modules that luac
uses expect a Proto. You could change them to get the function from the
stack and then extract the Proto.

BTW, you can avoid most of the internals of Lua by generating Lua source
instead of bytecode in combine, like the luac.lua that I posted recently:

static const Proto* combine(lua_State* L, int n)
{
 if (n==1)
  return toproto(L,-1);
 else
 {
  int i;
  Proto* f;
  for (i=0; i<n; i++) lua_pushliteral(L,"(function()end)();");
  lua_concat(L,n);
  luaL_loadbuffer(L,lua_tostring(L,-1),lua_objlen(L,-1),"=(" PROGNAME ")");
  f=toproto(L,-1);
  for (i=0; i<n; i++) f->p[i]=toproto(L,i-n-2);
  return f;
 }
}