Server IP : 172.67.216.182 / Your IP : 104.23.175.129 Web Server : Apache System : Linux krdc-ubuntu-s-2vcpu-4gb-amd-blr1-01.localdomain 5.15.0-142-generic #152-Ubuntu SMP Mon May 19 10:54:31 UTC 2025 x86_64 User : www ( 1000) PHP Version : 7.4.33 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /usr/share/swig4.0/lua/ |
Upload File : |
/* ----------------------------------------------------------------------------- * std_string.i * * std::string typemaps for LUA * ----------------------------------------------------------------------------- */ %{ #include <string> %} /* Only std::string and const std::string& are typemapped 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) */ namespace std { %naturalvar string; /* Bug report #1526022: Lua strings and std::string can contain embedded zero bytes Therefore a standard out typemap should not be: lua_pushstring(L,$1.c_str()); but lua_pushlstring(L,$1.data(),$1.size()); Similarly for getting the string $1 = (char*)lua_tostring(L, $input); becomes $1.assign(lua_tostring(L,$input),lua_rawlen(L,$input)); Not using: lua_tolstring() as this is only found in Lua 5.1 & not 5.0.2 */ %typemap(in,checkfn="lua_isstring") string %{$1.assign(lua_tostring(L,$input),lua_rawlen(L,$input));%} %typemap(out) string %{ lua_pushlstring(L,$1.data(),$1.size()); SWIG_arg++;%} %typemap(in,checkfn="lua_isstring") const string& ($*1_ltype temp) %{temp.assign(lua_tostring(L,$input),lua_rawlen(L,$input)); $1=&temp;%} %typemap(out) const string& %{ lua_pushlstring(L,$1->data(),$1->size()); SWIG_arg++;%} // for throwing of any kind of string, string ref's and string pointers // we convert all to lua strings %typemap(throws) string, string&, const string& %{ lua_pushlstring(L,$1.data(),$1.size()); SWIG_fail;%} %typemap(throws) string*, const string* %{ lua_pushlstring(L,$1->data(),$1->size()); SWIG_fail;%} %typecheck(SWIG_TYPECHECK_STRING) string, const string& { $1 = lua_isstring(L,$input); } /* std::string& can be wrapped, but you must inform SWIG if it is in or out eg: void fn(std::string& str); Is this an in/out/inout value? Therefore you need the usual %apply (std::string& INOUT) {std::string& str}; or %apply std::string& INOUT {std::string& str}; typemaps to tell SWIG what to do. */ %typemap(in) string &INPUT=const string &; %typemap(in, numinputs=0) string &OUTPUT ($*1_ltype temp) %{ $1 = &temp; %} %typemap(argout) string &OUTPUT %{ lua_pushlstring(L,$1->data(),$1->size()); SWIG_arg++;%} %typemap(in) string &INOUT =const string &; %typemap(argout) string &INOUT = string &OUTPUT; /* A really cut down version of the string class This provides basic mapping of lua strings <-> std::string and little else (the std::string has a lot of unneeded functions anyway) note: no fn's taking the const string& as this is overloaded by the const char* version */ class string { public: string(); string(const char*); unsigned int size() const; unsigned int length() const; bool empty() const; // no support for operator[] const char* c_str()const; const char* data()const; // assign does not return a copy of this object // (no point in a scripting language) void assign(const char*); // no support for all the other features // it's probably better to do it in lua }; }