lua-users home
lua-l archive

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


Hi, again.

I'm (still) a bit confused about 'loadlib' and dynamic C/Lua binding in
general. The idea behind loadlib's "callfromlib" function seems to be that
there's a Lua "wrapper" that takes care of declaring the function names
within Lua and then calling C/C++ in its body.

HOWEVER, the calling prototype within "callfromlib" is the normal "int
func(lua_State* L)" which means the called function should do Lua stack
handling itself. How can it do this? The normal lua code that it needs is on
the other side of the dll/so barrier.

IF YOU ARE USING CALLFROMLIB, please share some details on how you do it. Do
you handle 'lua_State' yourself ("stabbing") or have you compiled parts of
main lua code into your dll/so? If you have, which modules? Is Lua intended
to be used this way (e.g. are there dependency problems cutting away certain
modules from their normal lua surroundings)

Here's the function body of 'callfromlib' for those of you who don't have it
at hand:

	int callfromlib (lua_State *L)
	{
	  libtype lh = check_libhandle(L, 1);
	  const char *funcname = luaL_check_string(L, 2);
	  functype fn = loadfunc(lh, funcname);
	  if (fn) {
	    return fn(L);
	  }
	  else
	    lua_error(L, funcerror());
	  return 0;
	}

Thanks for the info. I'll do my app with static linking now, this is too
confusing. :)

-asko

P.S. Later, I still plan to do a proper "transparent static or dynamic
linkage" C / Lua interface. Anyone interested to share in it's design,
please say "I". ;)

--
Asko Kauppi
Flextronics Design Finland
Box 23, 39201 Kyröskoski, Finland
www.flextronics.com

###########################################
This message has been scanned by F-Secure Anti-Virus for Microsoft Exchange.