lua-users home
lua-l archive

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


>I found something in the documentation about pcall: "Then
>the program calls lua_pcall, which pops the chunk from the stack and
>runs it in protected mode", so I finally discovered what my error was
>=o)

The best way to do this would probably be to not lose it after lua_pcall. Do you really want to recompile every time? If not, you could do something like this (semi-pseudocode):

luaL_loadbuffer(...)

/* Check for error conditions */
/*...*/

/* Make another reference to the function on the stack */
/* for x = 1 to n ... */
lua_pushvalue(-1); 
lua_pcall(...);


This should allow you to call lua_pcall as many times as you want without having to recompile it.

That being said, recompilation is only as expensive if it needs to be. Code first, profile and optimize after. I wouldn't recommend it, but recompiling is certainly a valid option if it's not too expensive for your needs.

Regards,
-- Matthew P. Del Buono