1/* ----------------------------------------------------------------------------- 2 * See the LICENSE file for information on copyright, usage and redistribution 3 * of SWIG, and the README file for authors - http://www.swig.org/release.html. 4 * 5 * wchar.i 6 * 7 * Typemaps for the wchar_t type 8 * These are mapped to a Lua string and are passed around by value. 9 * 10 * ----------------------------------------------------------------------------- */ 11 12// note: only support for pointer right now, not fixed length strings 13// TODO: determine how long a const wchar_t* is so we can write wstr2str() 14// & do the output typemap 15 16%{ 17#include <stdlib.h> 18 19wchar_t* str2wstr(const char* str, int len) 20{ 21 wchar_t* p; 22 if (str==0 || len<1) return 0; 23 p=(wchar*)malloc((len+1)*sizeof(wchar_t)); 24 if (p==0) return 0; 25 if (mbstowcs(p, str, len)==-1) 26 { 27 free(p); 28 return 0; 29 } 30 p[len]=0; 31 return p; 32} 33%} 34 35%typemap( in, checkfn="lua_isstring" ) wchar_t* 36%{ 37$1 = str2wstr(lua_tostring( L, $input ),lua_strlen( L, $input )); 38if ($1==0) {lua_pushfstring(L,"Error in converting to wchar (arg %d)",$input);goto fail;} 39%} 40 41%typemap( freearg ) wchar_t* 42%{ 43free($1); 44%} 45 46%typemap(typecheck) wchar_t * = char *;