comparison lib/swig/swigwin-2.0.11/Lib/lua/wchar.i @ 1899:b3009adc0e2f

Adding swig, gitignore, hgignore
author Nomad
date Mon, 21 Oct 2013 10:42:27 +0200
parents
children
comparison
equal deleted inserted replaced
1867:eb580660bbbb 1899:b3009adc0e2f
1 /* -----------------------------------------------------------------------------
2 * wchar.i
3 *
4 * Typemaps for the wchar_t type
5 * These are mapped to a Lua string and are passed around by value.
6 * ----------------------------------------------------------------------------- */
7
8 // note: only support for pointer right now, not fixed length strings
9 // TODO: determine how long a const wchar_t* is so we can write wstr2str()
10 // & do the output typemap
11
12 %{
13 #include <stdlib.h>
14
15 wchar_t* str2wstr(const char *str, int len)
16 {
17 wchar_t* p;
18 if (str==0 || len<1) return 0;
19 p=(wchar *)malloc((len+1)*sizeof(wchar_t));
20 if (p==0) return 0;
21 if (mbstowcs(p, str, len)==-1)
22 {
23 free(p);
24 return 0;
25 }
26 p[len]=0;
27 return p;
28 }
29 %}
30
31 %typemap(in, checkfn="SWIG_lua_isnilstring", fragment="SWIG_lua_isnilstring") wchar_t *
32 %{
33 $1 = str2wstr(lua_tostring( L, $input ),lua_rawlen( L, $input ));
34 if ($1==0) {SWIG_Lua_pushferrstring(L,"Error in converting to wchar (arg %d)",$input);goto fail;}
35 %}
36
37 %typemap(freearg) wchar_t *
38 %{
39 free($1);
40 %}
41
42 %typemap(typecheck) wchar_t * = char *;