annotate lib/lua/lua-5.2.2/ldblib.c @ 2064:74f06d8a8017

Merge
author Ritor1
date Mon, 02 Dec 2013 20:43:28 +0600
parents 41cc4dd3c122
children
rev   line source
1866
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
1 /*
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
2 ** $Id: ldblib.c,v 1.132 2012/01/19 20:14:44 roberto Exp $
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
3 ** Interface from Lua to its debug API
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
4 ** See Copyright Notice in lua.h
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
5 */
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
6
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
7
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
8 #include <stdio.h>
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
9 #include <stdlib.h>
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
10 #include <string.h>
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
11
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
12 #define ldblib_c
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
13 #define LUA_LIB
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
14
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
15 #include "lua.h"
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
16
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
17 #include "lauxlib.h"
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
18 #include "lualib.h"
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
19
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
20
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
21 #define HOOKKEY "_HKEY"
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
22
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
23
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
24
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
25 static int db_getregistry (lua_State *L) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
26 lua_pushvalue(L, LUA_REGISTRYINDEX);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
27 return 1;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
28 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
29
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
30
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
31 static int db_getmetatable (lua_State *L) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
32 luaL_checkany(L, 1);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
33 if (!lua_getmetatable(L, 1)) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
34 lua_pushnil(L); /* no metatable */
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
35 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
36 return 1;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
37 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
38
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
39
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
40 static int db_setmetatable (lua_State *L) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
41 int t = lua_type(L, 2);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
42 luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2,
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
43 "nil or table expected");
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
44 lua_settop(L, 2);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
45 lua_setmetatable(L, 1);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
46 return 1; /* return 1st argument */
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
47 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
48
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
49
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
50 static int db_getuservalue (lua_State *L) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
51 if (lua_type(L, 1) != LUA_TUSERDATA)
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
52 lua_pushnil(L);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
53 else
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
54 lua_getuservalue(L, 1);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
55 return 1;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
56 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
57
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
58
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
59 static int db_setuservalue (lua_State *L) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
60 if (lua_type(L, 1) == LUA_TLIGHTUSERDATA)
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
61 luaL_argerror(L, 1, "full userdata expected, got light userdata");
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
62 luaL_checktype(L, 1, LUA_TUSERDATA);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
63 if (!lua_isnoneornil(L, 2))
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
64 luaL_checktype(L, 2, LUA_TTABLE);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
65 lua_settop(L, 2);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
66 lua_setuservalue(L, 1);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
67 return 1;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
68 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
69
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
70
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
71 static void settabss (lua_State *L, const char *i, const char *v) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
72 lua_pushstring(L, v);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
73 lua_setfield(L, -2, i);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
74 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
75
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
76
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
77 static void settabsi (lua_State *L, const char *i, int v) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
78 lua_pushinteger(L, v);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
79 lua_setfield(L, -2, i);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
80 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
81
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
82
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
83 static void settabsb (lua_State *L, const char *i, int v) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
84 lua_pushboolean(L, v);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
85 lua_setfield(L, -2, i);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
86 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
87
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
88
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
89 static lua_State *getthread (lua_State *L, int *arg) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
90 if (lua_isthread(L, 1)) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
91 *arg = 1;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
92 return lua_tothread(L, 1);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
93 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
94 else {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
95 *arg = 0;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
96 return L;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
97 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
98 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
99
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
100
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
101 static void treatstackoption (lua_State *L, lua_State *L1, const char *fname) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
102 if (L == L1) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
103 lua_pushvalue(L, -2);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
104 lua_remove(L, -3);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
105 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
106 else
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
107 lua_xmove(L1, L, 1);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
108 lua_setfield(L, -2, fname);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
109 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
110
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
111
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
112 static int db_getinfo (lua_State *L) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
113 lua_Debug ar;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
114 int arg;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
115 lua_State *L1 = getthread(L, &arg);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
116 const char *options = luaL_optstring(L, arg+2, "flnStu");
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
117 if (lua_isnumber(L, arg+1)) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
118 if (!lua_getstack(L1, (int)lua_tointeger(L, arg+1), &ar)) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
119 lua_pushnil(L); /* level out of range */
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
120 return 1;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
121 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
122 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
123 else if (lua_isfunction(L, arg+1)) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
124 lua_pushfstring(L, ">%s", options);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
125 options = lua_tostring(L, -1);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
126 lua_pushvalue(L, arg+1);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
127 lua_xmove(L, L1, 1);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
128 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
129 else
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
130 return luaL_argerror(L, arg+1, "function or level expected");
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
131 if (!lua_getinfo(L1, options, &ar))
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
132 return luaL_argerror(L, arg+2, "invalid option");
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
133 lua_createtable(L, 0, 2);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
134 if (strchr(options, 'S')) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
135 settabss(L, "source", ar.source);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
136 settabss(L, "short_src", ar.short_src);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
137 settabsi(L, "linedefined", ar.linedefined);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
138 settabsi(L, "lastlinedefined", ar.lastlinedefined);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
139 settabss(L, "what", ar.what);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
140 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
141 if (strchr(options, 'l'))
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
142 settabsi(L, "currentline", ar.currentline);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
143 if (strchr(options, 'u')) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
144 settabsi(L, "nups", ar.nups);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
145 settabsi(L, "nparams", ar.nparams);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
146 settabsb(L, "isvararg", ar.isvararg);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
147 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
148 if (strchr(options, 'n')) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
149 settabss(L, "name", ar.name);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
150 settabss(L, "namewhat", ar.namewhat);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
151 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
152 if (strchr(options, 't'))
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
153 settabsb(L, "istailcall", ar.istailcall);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
154 if (strchr(options, 'L'))
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
155 treatstackoption(L, L1, "activelines");
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
156 if (strchr(options, 'f'))
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
157 treatstackoption(L, L1, "func");
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
158 return 1; /* return table */
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
159 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
160
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
161
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
162 static int db_getlocal (lua_State *L) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
163 int arg;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
164 lua_State *L1 = getthread(L, &arg);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
165 lua_Debug ar;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
166 const char *name;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
167 int nvar = luaL_checkint(L, arg+2); /* local-variable index */
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
168 if (lua_isfunction(L, arg + 1)) { /* function argument? */
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
169 lua_pushvalue(L, arg + 1); /* push function */
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
170 lua_pushstring(L, lua_getlocal(L, NULL, nvar)); /* push local name */
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
171 return 1;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
172 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
173 else { /* stack-level argument */
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
174 if (!lua_getstack(L1, luaL_checkint(L, arg+1), &ar)) /* out of range? */
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
175 return luaL_argerror(L, arg+1, "level out of range");
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
176 name = lua_getlocal(L1, &ar, nvar);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
177 if (name) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
178 lua_xmove(L1, L, 1); /* push local value */
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
179 lua_pushstring(L, name); /* push name */
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
180 lua_pushvalue(L, -2); /* re-order */
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
181 return 2;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
182 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
183 else {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
184 lua_pushnil(L); /* no name (nor value) */
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
185 return 1;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
186 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
187 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
188 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
189
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
190
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
191 static int db_setlocal (lua_State *L) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
192 int arg;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
193 lua_State *L1 = getthread(L, &arg);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
194 lua_Debug ar;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
195 if (!lua_getstack(L1, luaL_checkint(L, arg+1), &ar)) /* out of range? */
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
196 return luaL_argerror(L, arg+1, "level out of range");
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
197 luaL_checkany(L, arg+3);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
198 lua_settop(L, arg+3);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
199 lua_xmove(L, L1, 1);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
200 lua_pushstring(L, lua_setlocal(L1, &ar, luaL_checkint(L, arg+2)));
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
201 return 1;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
202 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
203
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
204
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
205 static int auxupvalue (lua_State *L, int get) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
206 const char *name;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
207 int n = luaL_checkint(L, 2);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
208 luaL_checktype(L, 1, LUA_TFUNCTION);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
209 name = get ? lua_getupvalue(L, 1, n) : lua_setupvalue(L, 1, n);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
210 if (name == NULL) return 0;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
211 lua_pushstring(L, name);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
212 lua_insert(L, -(get+1));
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
213 return get + 1;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
214 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
215
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
216
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
217 static int db_getupvalue (lua_State *L) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
218 return auxupvalue(L, 1);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
219 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
220
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
221
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
222 static int db_setupvalue (lua_State *L) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
223 luaL_checkany(L, 3);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
224 return auxupvalue(L, 0);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
225 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
226
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
227
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
228 static int checkupval (lua_State *L, int argf, int argnup) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
229 lua_Debug ar;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
230 int nup = luaL_checkint(L, argnup);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
231 luaL_checktype(L, argf, LUA_TFUNCTION);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
232 lua_pushvalue(L, argf);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
233 lua_getinfo(L, ">u", &ar);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
234 luaL_argcheck(L, 1 <= nup && nup <= ar.nups, argnup, "invalid upvalue index");
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
235 return nup;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
236 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
237
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
238
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
239 static int db_upvalueid (lua_State *L) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
240 int n = checkupval(L, 1, 2);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
241 lua_pushlightuserdata(L, lua_upvalueid(L, 1, n));
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
242 return 1;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
243 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
244
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
245
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
246 static int db_upvaluejoin (lua_State *L) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
247 int n1 = checkupval(L, 1, 2);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
248 int n2 = checkupval(L, 3, 4);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
249 luaL_argcheck(L, !lua_iscfunction(L, 1), 1, "Lua function expected");
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
250 luaL_argcheck(L, !lua_iscfunction(L, 3), 3, "Lua function expected");
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
251 lua_upvaluejoin(L, 1, n1, 3, n2);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
252 return 0;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
253 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
254
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
255
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
256 #define gethooktable(L) luaL_getsubtable(L, LUA_REGISTRYINDEX, HOOKKEY)
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
257
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
258
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
259 static void hookf (lua_State *L, lua_Debug *ar) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
260 static const char *const hooknames[] =
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
261 {"call", "return", "line", "count", "tail call"};
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
262 gethooktable(L);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
263 lua_pushthread(L);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
264 lua_rawget(L, -2);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
265 if (lua_isfunction(L, -1)) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
266 lua_pushstring(L, hooknames[(int)ar->event]);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
267 if (ar->currentline >= 0)
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
268 lua_pushinteger(L, ar->currentline);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
269 else lua_pushnil(L);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
270 lua_assert(lua_getinfo(L, "lS", ar));
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
271 lua_call(L, 2, 0);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
272 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
273 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
274
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
275
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
276 static int makemask (const char *smask, int count) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
277 int mask = 0;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
278 if (strchr(smask, 'c')) mask |= LUA_MASKCALL;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
279 if (strchr(smask, 'r')) mask |= LUA_MASKRET;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
280 if (strchr(smask, 'l')) mask |= LUA_MASKLINE;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
281 if (count > 0) mask |= LUA_MASKCOUNT;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
282 return mask;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
283 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
284
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
285
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
286 static char *unmakemask (int mask, char *smask) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
287 int i = 0;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
288 if (mask & LUA_MASKCALL) smask[i++] = 'c';
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
289 if (mask & LUA_MASKRET) smask[i++] = 'r';
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
290 if (mask & LUA_MASKLINE) smask[i++] = 'l';
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
291 smask[i] = '\0';
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
292 return smask;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
293 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
294
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
295
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
296 static int db_sethook (lua_State *L) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
297 int arg, mask, count;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
298 lua_Hook func;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
299 lua_State *L1 = getthread(L, &arg);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
300 if (lua_isnoneornil(L, arg+1)) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
301 lua_settop(L, arg+1);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
302 func = NULL; mask = 0; count = 0; /* turn off hooks */
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
303 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
304 else {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
305 const char *smask = luaL_checkstring(L, arg+2);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
306 luaL_checktype(L, arg+1, LUA_TFUNCTION);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
307 count = luaL_optint(L, arg+3, 0);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
308 func = hookf; mask = makemask(smask, count);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
309 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
310 if (gethooktable(L) == 0) { /* creating hook table? */
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
311 lua_pushstring(L, "k");
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
312 lua_setfield(L, -2, "__mode"); /** hooktable.__mode = "k" */
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
313 lua_pushvalue(L, -1);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
314 lua_setmetatable(L, -2); /* setmetatable(hooktable) = hooktable */
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
315 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
316 lua_pushthread(L1); lua_xmove(L1, L, 1);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
317 lua_pushvalue(L, arg+1);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
318 lua_rawset(L, -3); /* set new hook */
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
319 lua_sethook(L1, func, mask, count); /* set hooks */
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
320 return 0;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
321 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
322
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
323
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
324 static int db_gethook (lua_State *L) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
325 int arg;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
326 lua_State *L1 = getthread(L, &arg);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
327 char buff[5];
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
328 int mask = lua_gethookmask(L1);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
329 lua_Hook hook = lua_gethook(L1);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
330 if (hook != NULL && hook != hookf) /* external hook? */
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
331 lua_pushliteral(L, "external hook");
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
332 else {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
333 gethooktable(L);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
334 lua_pushthread(L1); lua_xmove(L1, L, 1);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
335 lua_rawget(L, -2); /* get hook */
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
336 lua_remove(L, -2); /* remove hook table */
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
337 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
338 lua_pushstring(L, unmakemask(mask, buff));
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
339 lua_pushinteger(L, lua_gethookcount(L1));
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
340 return 3;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
341 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
342
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
343
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
344 static int db_debug (lua_State *L) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
345 for (;;) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
346 char buffer[250];
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
347 luai_writestringerror("%s", "lua_debug> ");
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
348 if (fgets(buffer, sizeof(buffer), stdin) == 0 ||
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
349 strcmp(buffer, "cont\n") == 0)
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
350 return 0;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
351 if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") ||
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
352 lua_pcall(L, 0, 0, 0))
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
353 luai_writestringerror("%s\n", lua_tostring(L, -1));
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
354 lua_settop(L, 0); /* remove eventual returns */
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
355 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
356 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
357
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
358
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
359 static int db_traceback (lua_State *L) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
360 int arg;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
361 lua_State *L1 = getthread(L, &arg);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
362 const char *msg = lua_tostring(L, arg + 1);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
363 if (msg == NULL && !lua_isnoneornil(L, arg + 1)) /* non-string 'msg'? */
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
364 lua_pushvalue(L, arg + 1); /* return it untouched */
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
365 else {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
366 int level = luaL_optint(L, arg + 2, (L == L1) ? 1 : 0);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
367 luaL_traceback(L, L1, msg, level);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
368 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
369 return 1;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
370 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
371
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
372
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
373 static const luaL_Reg dblib[] = {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
374 {"debug", db_debug},
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
375 {"getuservalue", db_getuservalue},
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
376 {"gethook", db_gethook},
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
377 {"getinfo", db_getinfo},
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
378 {"getlocal", db_getlocal},
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
379 {"getregistry", db_getregistry},
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
380 {"getmetatable", db_getmetatable},
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
381 {"getupvalue", db_getupvalue},
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
382 {"upvaluejoin", db_upvaluejoin},
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
383 {"upvalueid", db_upvalueid},
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
384 {"setuservalue", db_setuservalue},
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
385 {"sethook", db_sethook},
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
386 {"setlocal", db_setlocal},
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
387 {"setmetatable", db_setmetatable},
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
388 {"setupvalue", db_setupvalue},
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
389 {"traceback", db_traceback},
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
390 {NULL, NULL}
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
391 };
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
392
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
393
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
394 LUAMOD_API int luaopen_debug (lua_State *L) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
395 luaL_newlib(L, dblib);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
396 return 1;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
397 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
398