Re: How to access following data using Luabind
Tony Kostanjsek <[email protected]>
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
make sure your created and made your GL context current when you call any GL function, otherwise you'll most probably crash immediately. ________________________________ Von: Nicolas Goles <[email protected]> An: [email protected] Gesendet: Sonntag, den 20. Juni 2010, 3:07:38 Uhr Betreff: Re: [luabind] How to access following data using Luabind Hello, Thanks for your help. I was able to make it work, though I have 1 problem: This is my Placemark (trapezoid) C++ Class constructor: Placemark::Placemark(floatx1, floaty1, float x2, float y2, float x3, float y3, float x4, float y4) { vertex[0] = Vec2f(x1, y1); vertex[1] = Vec2f(x2, y2); vertex[2] = Vec2f(x3, y3); vertex[3] = Vec2f(x4, y4); //Create the vertex Dots for(int i = 0; i < 4; ++i) { VertexCircle*c= newVertexCircle(vertex[i], i); c->setParent(this); vertexDots.push_back(c); } glGenBuffers(1, &vbo); } However I bounded this constructor using luabind and called it in Lua with: p = Placemark(1.0, 2.0, 3.0, 4.0, 1.0, 2.0, 3.0, 4.0) The following piece of code in my C++ constructor: glGenBuffers(1, &vbo); //vbo is a Placemark private attribute. GLuint vbo; Makes my Application to Crash. I don't really know why, and it's easy to take that line out from my constructor, but still I was wondering if someone could enlighten me about why is it crashing when calling the OpenGL function glGenBuffers ?? Thanks. -------------------------------------------------------------- Nicolas Goles Domic Founder & Lead Programmer of Gando Games On Jun 18, 2010, at 4:42 AM, Iliya Trendafilov wrote: 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 > ------------------------------------------------------------------------------ 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