lua-users home
lua-l archive

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


On Sep 29, 2008, at 12:57 PM, Juan Manuel Alvarez wrote:
....
looking and 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)

Now I have some questions: How much does luaL_loadbuffer affect
performance? Is there any way to precompile a script from the C API
and call it multiple times? (since I only found a way to precompile it
from command-line).

luaL_loadbuffer is relatively expensive to the act of calling it's data, particularly when it is over uncompiled code since it must reparse the text each time.

You could do a lua_pushvalue to copy the chunk before you pcall it...

Ex:

luaL_loadbuffer(your chunk data)
for each time you want to call up your chunk
	lua_pushvalue(L, -1)  // copy it
	for each arg
		lua_push*
	lua_pcall(...)
	// handle values...
lua_pop(1)  // remove your chunk from the stack