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_int8_t, l4_int16_t, l4_int32_t, l4_mword_t,
23 int, short, long, signed char
24 %{$1 = ($type)lua_tointeger(L, $input);%}
26 %typemap(in,checkfn="lua_isnumber") l4_uint8_t, l4_uint16_t, l4_uint32_t, l4_addr_t,
27 l4_umword_t, unsigned int, unsigned short, unsigned long, unsigned char
28 %{//SWIG_contract_assert((lua_tonumber(L,$input)>=0),"number must not be negative")
29 $1 = ($type)lua_tointeger(L, $input);%}
31 %typemap(in,checkfn="lua_isnumber") enum SWIGTYPE
32 %{$1 = ($type)(int)lua_tointeger(L, $input);%}
34 %typemap(out) enum SWIGTYPE
35 %{ lua_pushinteger(L, (int)($1)); SWIG_arg++;%}
37 %typemap(out) l4_addr_t, l4_umword_t, l4_mword_t, l4_int32_t, l4_uint32_t,
38 l4_int8_t, l4_uint8_t, l4_int16_t, l4_uint16_t, l4_size_t,
39 int,short,long,unsigned int,unsigned short,unsigned long,
40 signed char,unsigned char
41 %{ lua_pushinteger(L, $1); SWIG_arg++;%}
43 %typemap(out) l4_int32_t*,int*,short*,long*,
44 unsigned int*,unsigned short*,unsigned long*,
45 signed char*,unsigned char*
46 %{ lua_pushinteger(L, *$1); SWIG_arg++;%}
48 %typemap(typecheck,precedence=SWIG_TYPECHECK_STRING) cxx::String, cxx::String const & {
49 $1 = lua_isstring(L, $input);
52 %typemap(in,checkfn="lua_isstring") cxx::String
53 %{$1 = cxx::String(lua_tostring(L, $input), lua_rawlen(L, $input));%}
55 %typemap(in,checkfn="lua_isstring") cxx::String const & (cxx::String tmp)
56 %{tmp = cxx::String(lua_tostring(L, $input), lua_rawlen(L, $input)); $1 = &tmp;%}
59 // typemap for big integers
60 %define %l4re_lua_bigint(name, type32, type, fmt, conversion)
61 %typemap(typecheck,precedence=SWIG_TYPECHECK_INTEGER) name
62 { $1 = lua_isnumber(L, $input) || lua_isstring(L, $input); }
67 #if SWIG_RECURSIVE_DEFINED LNUM_INT32
68 if (lua_isinteger(L, $input))
69 $1 = (type32)lua_tointeger(L, $input);
71 #elif SWIG_RECURSIVE_DEFINED LNUM_INT64
72 if (lua_isinteger(L, $input))
73 $1 = lua_tointeger(L, $input);
76 if (lua_isstring(L, $input))
79 char const *s = lua_tostring(L, $input);
80 type a = conversion(s, &e, 0);
81 if (s == e || *e != 0)
83 lua_pushfstring(L, "big number conversion error '%s'", s);
88 else if (lua_isnumber(L, $input))
89 $1 = lua_tonumber(L, $input);
92 lua_pushfstring(L, "big number expected (string or number) got %s",
93 lua_typename(L, lua_type(L, $input)));
99 %{lua_pushfstring(L, fmt, $1); ++SWIG_arg;%}
101 %l4re_lua_bigint(SWIG_BIGUINT, l4_uint32_t, l4_uint64_t, "0x%llx", strtoull)
102 %l4re_lua_bigint(SWIG_BIGINT, l4_int32_t, l4_int64_t, "0x%llx", strtoll)
104 %apply SWIG_BIGINT { l4_int64_t }
105 %apply SWIG_BIGUINT { l4_uint64_t }