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?
   return;
else
   attribute = 0;
   return;
end;

Is there a better way? 

Thanks for any input.