[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Translate String of Variable Name into Variable Value
- From: Etan Reisner <deryni@...>
- Date: Fri, 1 Jun 2007 21:38:31 -0400
On Fri, Jun 01, 2007 at 11:30:13AM -0400, Jerome Vuarand wrote:
> email@example.com wrote:
> > --
> > Right now, code like this works fine:
> > return my_object:item_in_slot(1) == 72
> > I'd like to be able to do something like:
> > my_object:item_in_slot(1) == magically_get_value_of("obj_food")
> This is not valid Lua code, so I assume that's C++. Unless you tell us
> how you did the C++ to Lua binding I'm affraid that nobody can give you
> any useful hint on how to implement your magical function. That's
> because how to bind C++ classes to Lua is not defined in the Lua spec,
> and there are many many ways to do it.
I don't see anything invalid in the code above, but that's sort of
irrelevant, you don't need a magical function to get at constant C++
values from lua you can just push them to lua as values and then use them
like normal lua values.
return my_object:item_in_slot(1) == obj_food
Assuming your C++ values are in fact constant that should work just fine,
you can of course use any table you want and not make them all globals if
you wanted to.