lua-users home
lua-l archive

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

It was thus said that the Great Murray S. Kucherawy once stated:
> If I pass a chunk to lua_load() and then use lua_dump() to get the
> compiled form, can I reuse that compiled form in different Lua states, or
> is it only good in the one in which it was compiled?

  I've done that successfully, but the routines in question do not refer to
local variables outside their scope, i.e.

	-- might not work because bar() refers to a local variable
	-- defined outside itself

	local foo
	function bar(x) return foo + x end

  You also need to make sure any global variables referenced in the compiled
function are available in the other Lua state as well.