first of all, I could wrap my C++ function which uses my custom string type. Here's how I did it.
This is my C++ function.
static void my_func(t_string message) {
do_something(message.c_str());
}
And this is the SWIG typemap.
%typemap(in) (t_string message)
{
if (!lua_isstring(L, 1)) {
SWIG_exception(SWIG_RuntimeError, "argument mismatch: string expected");
}
$1 = lua_tostring(L, 1);
}
While this seems to work fine, I wonder if it's possible to wrap my_func(t_string &message)
or my_func(const t_string &message)
.
The reason I'm asking this is because I think passing string by a reference would be a little faster than pass by value since I can avoid copying the string unnecessarily.
Please let me know if I'm wrong about this.