[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Executing a script multiple times
- From: "Juan Manuel Alvarez" <naicigam@...>
- Date: Mon, 29 Sep 2008 16:26:39 -0300
Thanks for all the quick replies!
I could make it work using lua_pushvalue(-1), but I am still having
problems with parameters.
I am doing the operations in the following order:
luaL_loadbuffer
lua_pushvalue(-1)
lua_pcall // to load the global table
lua_getglobal
lua_pushnumber // parameter 1
lua_pushnumber // parameter 2
lua_pushvalue(-1)
lua_pcall
The last pcall, gives me the error "attempt to call a number value".
The same sequence without the parameters works fine for me. Can you
please point me in the right direction?
Thanks in advance!
Juan M.
On Mon, Sep 29, 2008 at 2:11 PM, Matthew Paul Del Buono
<delbu9c1@erau.edu> wrote:
>>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
>