From: William S F. <ws...@fu...> - 2010-03-15 20:01:11
|
Gedalia Pasternak wrote: > > Hi list, > I've tried asking this on the swig mailing list but I didn't get any > input, so: > I've got a fairly simple question that I'd think would be obvious or in > the standard swig docs, but I haven't managed to puzzle it out. Is there a > straight forward typemap or other work around that would handle > converting lua's nil to c++'s NULL for an api like: > > c++: > foo->set_name(const char * name); > > lua: > foo:set_name(nil) > > it seems like I have to either make name an optional argument or pass > in "" > when what I want is to pass in NULL. > Is this a general limitation of most bindings or just swig (if it > even is a limitation of swig).. thanks for any suggestions > Lua knowledge isn't very good on this list, so I suggest you find out from elsewhere how you would do this manually in Lua, then we can advise which typemaps to change. To be honest, I'd expect nil to work when passed to any pointer, as you show, but give an exception if passed to C++ reference or object type. So I think the default behaviour would need to change. You need to override the SWIGTYPE* "in" typemap in Lib/luatypemaps.swg. William |