-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathluasql.c
63 lines (49 loc) · 1.28 KB
/
luasql.c
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
56
57
58
59
60
61
62
63
/*
** $Id: luasql.c 2494 2011-11-28 14:26:18Z wini $
** See Copyright Notice in license.html
*/
#include <string.h>
#ifndef BA_LIB
#define BA_LIB
#endif
#ifndef LUA_LIB
#define LUA_LIB
#endif
#include "barracuda.h"
#include "luasql.h"
/* this header cross depoendency is needed for the one
basnprintf() call */
/*
** Typical database error situation
*/
LUASQL_API int luasql_faildirect(lua_State *L, const char *err) {
lua_pushnil(L);
lua_pushstring(L, err);
return 2;
}
/*
** Create a metatable and leave it on top of the stack.
*/
LUASQL_API int luasql_createmeta (
lua_State *L, const char *name, const luaL_Reg *methods) {
if (!luaL_newmetatable (L, name))
return 0;
lua_pushvalue(L,BA_ENV_IX);
lua_pushvalue(L,SQL_ENV_IX);
luaL_setfuncs(L, methods, 2);
lua_pushliteral (L, "__index");
lua_pushvalue (L, -2);
lua_settable (L, -3);
lua_pushliteral (L, "__metatable");
lua_pushliteral (L,LUASQL_PREFIX" private");
lua_settable (L, -3);
return 1;
}
/*
** Define the metatable for the object on top of the stack
*/
LUASQL_API void luasql_setmeta (lua_State *L, const char *name) {
luaL_getmetatable (L, name);
baAssert( ! lua_isnil(L, -1) );
lua_setmetatable (L, -2);
}