[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: returning a list of strings to lua
- From: Miles Bader <miles@...>
- Date: Sat, 30 Oct 2010 05:49:33 +0900
Roger Durañona Vargas <firstname.lastname@example.org> 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
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:
%typemap(TYPEMAP_NAME) CXXTYPE "CODE"
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.