[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: how does swig manages std::strings in Lua?
- From: Miles Bader <miles@...>
- Date: Sat, 23 Feb 2008 23:21:05 +0900
Luo Hei <luo_hei@yahoo.es> writes:
> 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?
Last time I checked, swig was more functional with "char *" (it
automatically converts to/from lua strings). It's easy to handle
std::string _arguments_ (i.e., passing strings from Lua to C++
methods), simply by lying to swig about the types used in the
interface. [Just keep the std::string decl in your real interface,
but make corresponding the swig declaration use "const char *"; swig
will _think_ the interface uses const char*, and so will pass it
that type, and then C++ will happily do an implicit conversion from
const char* to std::string]
However I'm not sure how you can do it in for std::string return
values (other than using %extend and %rename to manually add
conversion wrappers for those methods that return std::string).
-Miles
--
Christian, n. One who follows the teachings of Christ so long as they are not
inconsistent with a life of sin.