From: Victor B. <so...@te...> - 2012-09-24 15:20:13
|
> I am trying to use dc:DrawLines but I cant understand how wxList or > wxPointList work: I have been searching on mailing list and code. I seems only for 2.9 is implemented. I would like a version with pairs of coordinates in a lua table. Could be something like: static int LUACALL wxLua_wxDC_DrawPolygon1(lua_State *L) { // get number of arguments int argCount = lua_gettop(L); // wxPolygonFillMode fill_style = wxODDEVEN_RULE wxPolygonFillMode fill_style = (argCount >= 5 ? (wxPolygonFillMode)wxlua_getenumtype(L, 5) : wxODDEVEN_RULE); // wxCoord yoffset = 0 wxCoord yoffset = (argCount >= 4 ? (wxCoord)wxlua_getnumbertype(L, 4) : 0); // wxCoord xoffset = 0 wxCoord xoffset = (argCount >= 3 ? (wxCoord)wxlua_getnumbertype(L, 3) : 0); // const wxList points luaL_checktype(L, 2, LUA_TTABLE); int n = lua_objlen(L, 2); /* get size of table */ double x,y; wxList<wxPoint> pointList; for (int i = 1; i <= n; i++) { lua_rawgeti(L, 2, i); /* get next point as {x,y} */ luaL_checktype(L, -1, LUA_TTABLE); lua_rawgeti(L,-1,1); if (!lua_isnumber(L, -1)) luaL_error(L, "coordinate x not a number"); x = lua_tonumber(L ,-1) lua_pop(L,1); lua_rawgeti(L,-1,2); if (!lua_isnumber(L, -1)) luaL_error(L, "coordinate Y not a number"); y = lua_tonumber(L ,-1) lua_pop(L,1); lua_pop(L,1); pointList:Append(wxPoint(x,y)); } //const wxList * points = (const wxList *)wxluaT_getuserdatatype(L, 2, wxluatype_wxList); // get this wxDC * self = (wxDC *)wxluaT_getuserdatatype(L, 1, wxluatype_wxDC); // call DrawPolygon self->DrawPolygon(&pointList, xoffset, yoffset, fill_style); return 0; } It is called as paintDC:DrawLines({{0,0},{20,40},{50,50}}) Similar for DrawLines. I dont know how to insert it in wxLua code and how you control function overloadings. Also perhaps you use something different than luaL_error. Best Regards Victor Bombi |