lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Roger Durañona Vargas <> writes:
> I want to have a function in my C code that returns a list of names,
> also, I need to use that function from lua scripts. But I have no idea
> about whats the best way to do this (my lua level is quite basic yet).
> Currently Im using Swig to generate my wrapper code, can somebody
> suggest me a way to do this?

You can use something called a "typemap" in swig to tell it "when you
see type XXX in the C++ code, run this code to translate it to the
other language".

I've only used it for arguments (not return values), but it's not so
hard if you know how to manipulate values using Lua's C interface.

The documentation is here:

The basic syntax is:


As I said, I haven't done it for return-values, but the doc mentions the
"out", "ret", and "newfree" typemaps related to return values (look in
the doc for examples of how to use them).

Presumably you'd have your C++ function return something like
std::vector<std::string>, and then give that for CXXTYPE when writing
your translation typemap.


Inhumanity, n. One of the signal and characteristic qualities of humanity.