2 * Copyright (C) 2012 Toni Gundogdu <legatvs@gmail.com>
4 * This file is part of libquvi <http://quvi.sourceforge.net/>.
6 * This library is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU Affero General Public
8 * License as published by the Free Software Foundation, either
9 * version 3 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General
17 * Public License along with this library. If not, see
18 * <http://www.gnu.org/licenses/>.
28 #include "lua/getfield.h"
30 gpointer
l_get_reg_userdata(lua_State
*l
, const gchar
*k
)
33 lua_gettable(l
, LUA_REGISTRYINDEX
);
35 if (!lua_isuserdata(l
, -1))
36 luaL_error(l
, "expected to find the key `%s' in LUA_REGISTRYINDEX", k
);
38 return ((gpointer
) lua_touserdata(l
, -1));
41 #ifdef _1 /* Unused */
43 static const gchar
*_E
=
44 "%s: %s: expected to find the key `%s' in the returned table";
46 #define _pop(ltype, ctype, dval) \
49 lua_pushstring(l ,k); \
50 lua_gettable(l, -2); \
51 if (!lua_is##ltype(l, -1)) \
52 luaL_error(l, _E, script_path, script_func, k); \
53 r = lua_to##ltype(l, -1); \
58 const gchar
*l_getfield_s(lua_State
*l
, const gchar
*k
,
59 const gchar
*script_path
,
60 const gchar
*script_func
)
62 _pop(string
, const gchar
*, NULL
);
65 const gdouble
l_getfield_n(lua_State
*l
, const gchar
*k
,
66 const gchar
*script_path
,
67 const gchar
*script_func
)
69 _pop(number
, gdouble
, 0);
72 const gboolean
l_getfield_b(lua_State
*l
, const gchar
*k
,
73 const gchar
*script_path
,
74 const gchar
*script_func
)
76 _pop(boolean
, gboolean
, FALSE
);
79 QuviError
l_getfield_table_iter_s(lua_State
*l
,
82 const gchar
*script_path
,
83 const gchar
*script_func
,
84 l_callback_getfield_table_iter_s cb
)
86 QuviError rc
= QUVI_OK
;
91 if (!lua_istable(l
, -1))
93 luaL_error(l
, "%s: %s: expected to find the table `%s'",
94 script_path
, script_func
, k
);
99 while (lua_next(l
, -2) && rc
== QUVI_OK
)
101 rc
= (cb
)(dst
, lua_tostring(l
, -1));
109 #endif /* _1, unused */
111 /* vim: set ts=2 sw=2 tw=72 expandtab: */