3 * (c) 2011 Alexander Warg <warg@os.inf.tu-dresden.de>
4 * economic rights: Technische Universität Dresden (Germany)
6 * This file is part of TUD:OS and distributed under the terms of the
7 * GNU General Public License 2.
8 * Please see the COPYING-GPL-2 file for details.
12 #define SWIG_RECURSIVE_DEFINED defined
15 /* Refined typemaps for our L4 types and our lua lib with integer support */
17 %typemap(typecheck,precedence=SWIG_TYPECHECK_INTEGER) l4_int8_t,l4int16_t,l4_int32_t,
18 l4_mword_t,l4uint8_t,l4_uint16_t,l4_uint32_t,l4_umword_t,
20 {$1 = lua_isnumber(L, $input);}
22 %typemap(in,checkfn="lua_isnumber") l4_int32_t, int, short, long, signed char
23 %{$1 = ($type)lua_tointeger(L, $input);%}
25 %typemap(in,checkfn="lua_isnumber") l4_addr_t, l4_umword_t, unsigned int, unsigned short,
26 unsigned long, unsigned char
27 %{//SWIG_contract_assert((lua_tonumber(L,$input)>=0),"number must not be negative")
28 $1 = ($type)lua_tointeger(L, $input);%}
30 %typemap(in,checkfn="lua_isnumber") enum SWIGTYPE
31 %{$1 = ($type)(int)lua_tointeger(L, $input);%}
33 %typemap(out) enum SWIGTYPE
34 %{ lua_pushinteger(L, (int)($1)); SWIG_arg++;%}
36 %typemap(out) l4_addr_t,l4_umword_t,l4_int32_t,int,short,long,
37 unsigned int,unsigned short,unsigned long,
38 signed char,unsigned char
39 %{ lua_pushinteger(L, $1); SWIG_arg++;%}
41 %typemap(out) l4_int32_t*,int*,short*,long*,
42 unsigned int*,unsigned short*,unsigned long*,
43 signed char*,unsigned char*
44 %{ lua_pushinteger(L, *$1); SWIG_arg++;%}
46 %typemap(typecheck,precedence=SWIG_TYPECHECK_INTEGER) l4_addr_t,l4_umword_t,l4_int32_t {
47 $1 = lua_isnumber(L, $input);
50 %typemap(typecheck,precedence=SWIG_TYPECHECK_STRING) cxx::String, cxx::String const & {
51 $1 = lua_isstring(L, $input);
54 %typemap(in,checkfn="lua_isstring") cxx::String
55 %{$1 = cxx::String(lua_tostring(L, $input), lua_rawlen(L, $input));%}
57 %typemap(in,checkfn="lua_isstring") cxx::String const & (cxx::String tmp)
58 %{tmp = cxx::String(lua_tostring(L, $input), lua_rawlen(L, $input)); $1 = &tmp;%}
61 // typemap for big integers
62 %define %l4re_lua_bigint(name, type32, type, fmt, conversion)
63 %typemap(typecheck,precedence=SWIG_TYPECHECK_INTEGER) name
64 { $1 = lua_isnumber(L, $input) || lua_isstring(L, $input); }
69 #if SWIG_RECURSIVE_DEFINED LNUM_INT32
70 if (lua_isinteger(L, $input))
71 $1 = (type32)lua_tointeger(L, $input);
73 #elif SWIG_RECURSIVE_DEFINED LNUM_INT64
74 if (lua_isinteger(L, $input))
75 $1 = lua_tointeger(L, $input);
78 if (lua_isstring(L, $input))
81 char const *s = lua_tostring(L, $input);
82 type a = conversion(s, &e, 0);
83 if (s == e || *e != 0)
85 lua_pushfstring(L, "big number conversion error '%s'", s);
90 else if (lua_isnumber(L, $input))
91 $1 = lua_tonumber(L, $input);
94 lua_pushfstring(L, "big number expected (string or number) got %s",
95 lua_typename(L, lua_type(L, $input)));
101 %{lua_pushfstring(L, fmt, $1); ++SWIG_arg;%}
103 %l4re_lua_bigint(SWIG_BIGUINT, l4_uint32_t, l4_uint64_t, "0x%llx", strtoull)
104 %l4re_lua_bigint(SWIG_BIGINT, l4_int32_t, l4_int64_t, "0x%llx", strtoll)
106 %apply SWIG_BIGINT { l4_int64_t }
107 %apply SWIG_BIGUINT { l4_uint64_t }