Jump to content
  • Advertisement
Sign in to follow this  
Mr.Big

Passing Lua Array to C++ Array

This topic is 2606 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

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? Edited by Mr. Big

Share this post


Link to post
Share on other sites
Advertisement
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*.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!