lua-users home
lua-l archive

Re: how does swig manages std::strings in Lua?

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


Luo Hei wrote:
Well, thats the question. I would like to pass strings to lua scripts
via swig generated wrappers. Can i use std::string or should I fall back
to C style strings?
If you use the following line, you get some support for std::string.
%include "std_string.i"
The file std_string.i is included in the Lua bindng files of swig (at least with version 1.3.33). Here is a little documentation from the top of std_string.i.
/*
Only std::string and const std::string& are typemaped
they are converted to the Lua strings automatically
std::string& and std::string* are not
they must be explicitly managed (see below)
eg.
std::string test_value(std::string x) {
 return x;
}
can be used as
s="hello world"
s2=test_value(s)
assert(s==s2)
*/

AltStyle によって変換されたページ (->オリジナル) /