lua-users home
lua-l archive

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

> 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 :)