1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
/*
** Lua eXtended library helpers
*/
#define lxsyslib_c
#define LUA_LIB
#include <lua/lprefix.h>
#include <errno.h>
#include <locale.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <lua/lua.h>
#include <lua/lauxlib.h>
#include <lua/lualib.h>
#include "lxlib.h"
bool lx_checkboolean(lua_State *L, int arg) {
if (!lua_isboolean(L, arg)) {
luaL_argerror(L, arg, "expected boolean");
}
return lua_toboolean(L, arg);
}
void* lx_checklightudata(lua_State *L, int arg) {
if (!lua_islightuserdata(L, arg)) {
luaL_argerror(L, arg, "expected light userdata");
}
return lua_touserdata(L, arg);
}
void setintfield (lua_State *L, const char *key, int value) {
lua_pushinteger(L, value);
lua_setfield(L, -2, key);
}
void setstrfield (lua_State *L, const char *key, const char* value) {
lua_pushstring(L, value);
lua_setfield(L, -2, key);
}
int getintfield(lua_State *L, int arg, const char *key) {
lua_getfield(L, arg, key);
int v = luaL_checkinteger(L, -1);
lua_pop(L, 1);
return v;
}
|