Skip to main content
gamedev.net
🔒 Locked

Passing Lua Array to C++ Array

Started by Mr.Big 0 replies 1.8k views
Original Post
Mr.Big
Mr.Big
I have no idea why this wont work. Needs a new set of (more experienced) eyes to take a look at it.

Lua table;
maplist = {"sand.obj", "jungle.obj", "cubes.obj"}


C++


//populate the map list array
stringw maplist[50];
int i = 0;

lua_getglobal(L, "maplist");
lua_pushnil(L);

while(lua_next(L, -2))
{
maplist = (stringw)lua_tostring(L, -1);
i++;

lua_pop(L, 1);
}
lua_pop(L, 1);



Basically its just filling the array with random garbage.
If i change it to maplist[0] it works. (obviously overwrites it twice though)

Any tips? Maybe even a better way to do it?


Edit: Ok? Not initializing the array was apparently the problem. *shrug* Resolved now, I guess?
HappyCoder
HappyCoder
What is a stringw?

Depending on what that is this line of code may be your problem.


maplist = (stringw)lua_tostring(L, -1);


lua_tostring reuturns a const char*.
My current game project Platform RPG

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.