Re: How to access following data using Luabind
Iliya Trendafilov <[email protected]>
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
Hi,
Just to access the data from your script in C++ you can do something like this:
luabind::object_cast<double>(luabind::globals(lua)["polygons"]["vertex"][1][1])
// returns x1 of the first trapezoid
The return of every operator[] above is luabind::object that you could "cache".
That said, I'd rather register Color3f and Trapezoid classes with at
least their constructors, then write a tiny glue lua script
polygonInsances = {}
for i = 1, #polygons.vertex
do
local v = polygons.vertex[i]
local c = polygons.color[i]
polygonInstances[i] = Trapezoid(v[1][1], v[1][2], v[2][1],
v[2][2], v[3][1], v[3][2], v[4][1], v[4][2], Color3f(c[1], c[2],
c[3]))
done
And then use polygonInstances:
luabind::object_cast<Trapezoid>(luabind::globals(lua)["polygonInstances"][1]);
// returns the first trapezoid
Hope that helps.
(WARNING: None of the code above has been compiled or run through Lua
interpreter)
On Fri, Jun 18, 2010 at 8:54 AM, Nicolas Goles <[email protected]> wrote:
> Hello,
> I'm quite new to Luabind, I'm trying to access the following data
> polygons = {
> -- 3 "different" Trapezoidal polygons, 4 vertex (x,y) each.
> vertex = {
> {{1,0}, {1,10}, {21,30}, {25,35}},
> {{1,0}, {1,10}, {21,30}, {25,35}},
> {{1,0}, {1,10}, {21,30}, {25,35}},
> },
> -- 3 Colors ( R , G , B) one for each polygon
> color = {
> {1,0,0},
> {0,1,0},
> {0,0,1},
> }
> }
> it represents 3 "different" trapezoidal polygons, each one with a color.
> In my Application, I have a C++ class "Trapezoid" that has a constructor
> that receives 8 floats (x1,y2 , x2, y2.... ) and a color.
> Trapezoid::Trapezoid(x1, y1, x2, y2, x3, y3, x4, y4, Color3f color);
> What would be the correct way to access this Lua script using luabind? I
> have been struggling all day.
> Sorry if this is noobish, but haven't found any clear solutions for this (
> most of the examples focus on executing functions, and more complex stuff )
> What would you guys suggest ?
> Thanks!
> _Nicolas
> ------------------------------------------------------------------------------
> ThinkGeek and WIRED's GeekDad team up for the Ultimate
> GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
> lucky parental unit. See the prize list and enter to win:
> http://p.sf.net/sfu/thinkgeek-promo
> _______________________________________________
> luabind-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/luabind-user
>
>
------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
lucky parental unit. See the prize list and enter to win:
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user