lua-users home
lua-l archive

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


I had some trouble earlier today trying to get a value from a table
from C. Is there a simple way to do this (maybe I did something wrong,
or I've missed something??)

I've tried code similar to lua_getglobal(L, "table.value"); which
doesn't seem to work. The work around I've used for the time being is
as follows:

double Config::GetValue(const char *name, double defaultValue)
  char string[80] = "tempN=";

  strcat(string, name);
  lua_dostring(L, string);

  lua_getglobal(L, "tempN");
  int top = lua_gettop(L);
  if(lua_isnumber(L, top))
    return lua_tonumber(L, top);

  return defaultValue;

Can anyone offer me a better solution?