[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: When to clean the stack?
- From: "Bram Vaessen" <bram.vaessen@...>
- Date: Sun, 17 Nov 2002 08:53:27 +0100
> I have a script for which I want a return value.
> Usually something like this:
> scriptstring = "strength = 10 agility = 10 calculated_attribute =
> strength + agility"
> (of course, this is a nonsense script, but you see what I mean).
>
> How do I get the "calculated_attribute" back out of LUA?
> I assume I would use lua_getglobal() -- how do you use this function?
>
> I was thinking it would be something like this (in pseudocode):
>
> lua_dostring(scriptstring);
> lua_getglobal(L,"calculated_attribute");
> if (lua_isnumber(L,???) // what to put here?
> attribute = lua_tonumber(L,???);
> // should I clean the stack here? or does lua_tonumber do it?
you can put lua_gettop(L) there.
after the script you can use lua_settop(0) to clean the stack...
P.S. I'm not a lua expert but this is what I use and it seems to work :)