lua-users home
lua-l archive

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


On Fri, Jun 01, 2007 at 11:30:13AM -0400, Jerome Vuarand wrote:
> spam@bitlet.com wrote:
<snip>
> > --
> > 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.

lua_pushinteger(L, obj_food);
lua_setglobal(L, "obj_food");
--
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.

	-Etan