Jump to content
  • Advertisement
Sign in to follow this  
medevilenemy

STL Maps and SWIG/Lua

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

Haven't been on in a while, so I'll start with "Hello All!". Ok, now that I have that out of the way, I'm having some trouble figuring out how to get SWIG to bing a stl map from int to an object pointer to lua. It compiles just fine, but I can't seem to get it to work. In the past, owl would be the one to talk to about SWIG stuff, but seeing as he is banned for some reason: Does anyone else have any experience with SWIG?

Specifically it is a map<int, Object*> where Object is a class of mine. It is wrapping an instance called Master_Object_Map. When I call Master_Object_Map:get(indexIwant) it just prints out the error "index not found" (I'm testing with known indices)

Share this post


Link to post
Share on other sites
Advertisement
well, the map itself is defined as: map<int, Object*> Master_Object_Map;

Whenever a new object is created, a pointer to it gets added to that map with its UID (starting at 0) as its key. The swig .i file contains the object class, as well as:

%template(MapIntObj) map<int, Object*>;

map<int, Object*> Master_Object_Map;

And this is the lua code I was playing with as a silly little simple test:

io.output("luatestoutputfunfunfunfunfun.txt")
io.output(objects.Master_Object_Map:get(0):Get_UID())
io.output(objects.Master_Object_Map:get(1):Get_UID())
io.output(objects.Master_Object_Map:get(2):Get_UID())
io.output(objects.Master_Object_Map:get(3):Get_UID())
io.output(objects.Master_Object_Map:get(4):Get_UID())
io.output(objects.Master_Object_Map:get(5):Get_UID())

The error I get from lua is as I stated above. Going by the generated swig wrapper code, it came from get(). (note, objects is the module name)

Share this post


Link to post
Share on other sites
Eh, I don't have an answer for you. Sorry. But I can recommend you join the SWIG-users email list and ask there. I suspect there are people on that list who could solve your problem. The SWIG site has a mailing lists page with info on how to access the lists.

Share this post


Link to post
Share on other sites
I figured it out (when in doubt, rely on the engineer's propensity to do good work at 3am)... This will sound silly, but I was looking for entries in the map in a script that is run before the relevant entries actually spawn and was therefore recieving what *appeared* like the map not having been bound properly. Progress goes marching on.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!