STL Maps and SWIG/Lua

Started by
4 comments, last by medevilenemy 12 years, 1 month ago
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)
There was a saying we had in college: Those who walk into the engineering building are never quite the same when they walk out.
Advertisement
Can you post a bit of code?

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

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)
There was a saying we had in college: Those who walk into the engineering building are never quite the same when they walk out.
No takers? Guess SWIG isn't terribly well known.
There was a saying we had in college: Those who walk into the engineering building are never quite the same when they walk out.
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.
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.
There was a saying we had in college: Those who walk into the engineering building are never quite the same when they walk out.

This topic is closed to new replies.

Advertisement