• Advertisement
Sign in to follow this  

LUA : Read a table of objects

This topic is 3422 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all! I'm new here :), i've some problems to use Lua into my games for loading my levels... I just want to read a table of object like this : -------- Level1.lua objects = { { type = 6, x=16, y=16, }, { type = 6, x=16, y=16 }, { type = 6, x=16, y=16 }, ... ------------- But i don't realy understand how a table like this work to use it into a c++ project. Here's my main.cpp : -------- Main.cpp typedef struct{ int type, x, y; } SPRITE; void LoadMap() // Chargement d'un niveau { lua_State * L = lua_open(); luaL_openlibs(L); if (luaL_dofile(L, "Level1.lua")!=0){} lua_settop(L,0); lua_getglobal(L,"objects"); SPRITE tmp_spr; int tableindex = lua_gettop(L); lua_pushnil(L); while(lua_next(L,tableindex)) { lua_pushvalue(L,-2); lua_gettable(L, -2); lua_pushstring(L, "type"); lua_gettable(L, -2); tmp_spr.type=(int)lua_tonumber(L, -2); lua_pop(L, 1); lua_pushstring(L, "x"); lua_gettable(L, -2); tmp_spr.x=(int)lua_tonumber(L, -2); lua_pop(L, 1); lua_pushstring(L, "y"); lua_gettable(L, -2); tmp_spr.y=(int)lua_tonumber(L, -2); lua_pop(L, 1); MakeObject(tmp_spr); lua_pop(L, 1); } } ----------------- With this code, i optain a black screen and the application freeze. Anyone can help me? Thk's in advance!

Share this post


Link to post
Share on other sites
Advertisement
You should have a lot more assertions in that code (offhand, I can see about ten places for that). That should uncover your problem easily.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement