annotate lib/swig/swigwin-2.0.11/Lib/lua/wchar.i @ 1916:918a8cebd7a4

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