lua-users home
lua-l archive

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


On the C side you could do something like
const char* value = config->getValue("install")->getValue("location");
or
const char* value = config->getValue("install", "location"); if you like
variable args in C

On the Lua side, something like
return dostring('return config.' .. key)
would work but not be very efficient (does that matter?).

Russ


> From: "J. Perkins" <jason@379.com>
> Reply-To: lua-l@tecgraf.puc-rio.br
> Date: Fri, 22 Mar 2002 13:32:26 -0500
> To: Multiple recipients of list <lua-l@tecgraf.puc-rio.br>
> Subject: Index table from string?
> 
> I sent a similar email yesterday bit it appears to have never made
> it to the list. Apologies this ends up getting posted twice.
> 
> I've got a Lua "class" which manages configuration information. It's
> a hierarchical set of tables, something like, so from Lua I can do
> stuff like:
> 
> config.install.location = "/home/user/myApp"
> 
> Like a registry kind of thing. I would like to be able to call into
> this "class" from C and ask for values, like
> 
> const char* value = config->getValue("install.location");
> 
> If I have a Lua function that looks like this:
> 
> function Registry:getValue(key)
> 
> is there a clever way to get the value referenced by the string
> 'key'? Intuitively what I want is:
> 
> return self[key]
> 
> but self["install.location"] obviously doesn't work. I can parse out
> the '.' characters and step down the tree manually but that seems
> so...un-Lua.
> 
> Thanks for the help (again),
> Jason
> 
> 
>