Sun, 23 Nov 2008 04:12:04 +0000
Cleanup and commenting
1 | 1 | #include <string.h> |
2 | #include <stdio.h> | |
3 | #include <stdlib.h> | |
4 | ||
5 | #include <lua.h> | |
6 | #include <lauxlib.h> | |
7 | #include <lualib.h> | |
8 | ||
9 | #if !defined(LUA_VERSION_NUM) || (LUA_VERSION_NUM < 501) | |
10 | #include <compat-5.1.h> | |
11 | #endif | |
12 | ||
2 | 13 | /* |
14 | * | |
15 | * Table construction helper functions | |
16 | * | |
17 | * LUA_PUSH_ATTRIB_* creates string indexed (hashmap) | |
18 | * LUA_PUSH_ATTRIB_* creates integer indexed (array) | |
19 | * | |
20 | */ | |
1 | 21 | |
22 | #define LUA_PUSH_ATTRIB_INT(n, v) \ | |
23 | lua_pushstring(L, n); \ | |
24 | lua_pushinteger(L, v); \ | |
25 | lua_rawset(L, -3); | |
26 | ||
27 | #define LUA_PUSH_ATTRIB_FLOAT(n, v) \ | |
28 | lua_pushstring(L, n); \ | |
29 | lua_pushnumber(L, v); \ | |
30 | lua_rawset(L, -3); | |
31 | ||
32 | #define LUA_PUSH_ATTRIB_STRING(n, v) \ | |
33 | lua_pushstring(L, n); \ | |
34 | lua_pushstring(L, v); \ | |
35 | lua_rawset(L, -3); | |
36 | ||
37 | #define LUA_PUSH_ATTRIB_BOOL(n, v) \ | |
38 | lua_pushstring(L, n); \ | |
39 | lua_pushboolean(L, v); \ | |
40 | lua_rawset(L, -3); | |
41 | ||
42 | #define LUA_PUSH_ATTRIB_NIL(n) \ | |
43 | lua_pushstring(L, n); \ | |
44 | lua_pushnil(L); \ | |
45 | lua_rawset(L, -3); | |
46 | ||
47 | ||
48 | ||
49 | #define LUA_PUSH_ARRAY_INT(n, v) \ | |
50 | lua_pushinteger(L, v); \ | |
51 | lua_rawseti(L, -2, n); \ | |
52 | n++; | |
53 | ||
54 | #define LUA_PUSH_ARRAY_FLOAT(n, v) \ | |
55 | lua_pushnumber(L, v); \ | |
56 | lua_rawseti(L, -2, n); \ | |
57 | n++; | |
58 | ||
59 | #define LUA_PUSH_ARRAY_STRING(n, v) \ | |
60 | lua_pushstring(L, v); \ | |
61 | lua_rawseti(L, -2, n); \ | |
62 | n++; | |
63 | ||
64 | #define LUA_PUSH_ARRAY_BOOL(n, v) \ | |
65 | lua_pushboolean(L, v); \ | |
66 | lua_rawseti(L, -2, n); \ | |
67 | n++; | |
68 | ||
69 | #define LUA_PUSH_ARRAY_NIL(n) \ | |
70 | lua_pushnil(L); \ | |
71 | lua_rawseti(L, -2, n); \ | |
72 | n++; | |
73 | ||
2 | 74 | /* |
75 | * | |
76 | * Describes SQL to Lua API conversions | |
77 | * | |
78 | */ | |
1 | 79 | |
80 | typedef enum lua_push_type { | |
81 | LUA_PUSH_NIL = 0, | |
82 | LUA_PUSH_INTEGER, | |
83 | LUA_PUSH_NUMBER, | |
84 | LUA_PUSH_STRING, | |
85 | LUA_PUSH_BOOLEAN, | |
86 | ||
87 | LUA_PUSH_MAX | |
88 | } lua_push_type_t; | |
89 |