@@ -38,49 +38,6 @@ static void checkstack (lua_State *L, lua_State *L1, int n) {
38
38
}
39
39
40
40
41
- static int db_getregistry (lua_State * L ) {
42
- lua_pushvalue (L , LUA_REGISTRYINDEX );
43
- return 1 ;
44
- }
45
-
46
-
47
- static int db_getmetatable (lua_State * L ) {
48
- luaL_checkany (L , 1 );
49
- if (!lua_getmetatable (L , 1 )) {
50
- lua_pushnil (L ); /* no metatable */
51
- }
52
- return 1 ;
53
- }
54
-
55
-
56
- static int db_setmetatable (lua_State * L ) {
57
- int t = lua_type (L , 2 );
58
- luaL_argcheck (L , t == LUA_TNIL || t == LUA_TTABLE , 2 ,
59
- "nil or table expected" );
60
- lua_settop (L , 2 );
61
- lua_setmetatable (L , 1 );
62
- return 1 ; /* return 1st argument */
63
- }
64
-
65
-
66
- static int db_getuservalue (lua_State * L ) {
67
- if (lua_type (L , 1 ) != LUA_TUSERDATA )
68
- lua_pushnil (L );
69
- else
70
- lua_getuservalue (L , 1 );
71
- return 1 ;
72
- }
73
-
74
-
75
- static int db_setuservalue (lua_State * L ) {
76
- luaL_checktype (L , 1 , LUA_TUSERDATA );
77
- luaL_checkany (L , 2 );
78
- lua_settop (L , 2 );
79
- lua_setuservalue (L , 1 );
80
- return 1 ;
81
- }
82
-
83
-
84
41
/*
85
42
** Auxiliary function used by several library functions: check for
86
43
** an optional thread as function's first argument and set 'arg' with
@@ -142,7 +99,7 @@ static void treatstackoption (lua_State *L, lua_State *L1, const char *fname) {
142
99
** two optional outputs (function and line table) from function
143
100
** 'lua_getinfo'.
144
101
*/
145
- static int db_getinfo (lua_State * L ) {
102
+ extern int db_getinfo (lua_State * L ) {
146
103
lua_Debug ar ;
147
104
int arg ;
148
105
lua_State * L1 = getthread (L , & arg );
@@ -190,114 +147,6 @@ static int db_getinfo (lua_State *L) {
190
147
}
191
148
192
149
193
- static int db_getlocal (lua_State * L ) {
194
- int arg ;
195
- lua_State * L1 = getthread (L , & arg );
196
- lua_Debug ar ;
197
- const char * name ;
198
- int nvar = (int )luaL_checkinteger (L , arg + 2 ); /* local-variable index */
199
- if (lua_isfunction (L , arg + 1 )) { /* function argument? */
200
- lua_pushvalue (L , arg + 1 ); /* push function */
201
- lua_pushstring (L , lua_getlocal (L , NULL , nvar )); /* push local name */
202
- return 1 ; /* return only name (there is no value) */
203
- }
204
- else { /* stack-level argument */
205
- int level = (int )luaL_checkinteger (L , arg + 1 );
206
- if (!lua_getstack (L1 , level , & ar )) /* out of range? */
207
- return luaL_argerror (L , arg + 1 , "level out of range" );
208
- checkstack (L , L1 , 1 );
209
- name = lua_getlocal (L1 , & ar , nvar );
210
- if (name ) {
211
- lua_xmove (L1 , L , 1 ); /* move local value */
212
- lua_pushstring (L , name ); /* push name */
213
- lua_rotate (L , -2 , 1 ); /* re-order */
214
- return 2 ;
215
- }
216
- else {
217
- lua_pushnil (L ); /* no name (nor value) */
218
- return 1 ;
219
- }
220
- }
221
- }
222
-
223
-
224
- static int db_setlocal (lua_State * L ) {
225
- int arg ;
226
- const char * name ;
227
- lua_State * L1 = getthread (L , & arg );
228
- lua_Debug ar ;
229
- int level = (int )luaL_checkinteger (L , arg + 1 );
230
- int nvar = (int )luaL_checkinteger (L , arg + 2 );
231
- if (!lua_getstack (L1 , level , & ar )) /* out of range? */
232
- return luaL_argerror (L , arg + 1 , "level out of range" );
233
- luaL_checkany (L , arg + 3 );
234
- lua_settop (L , arg + 3 );
235
- checkstack (L , L1 , 1 );
236
- lua_xmove (L , L1 , 1 );
237
- name = lua_setlocal (L1 , & ar , nvar );
238
- if (name == NULL )
239
- lua_pop (L1 , 1 ); /* pop value (if not popped by 'lua_setlocal') */
240
- lua_pushstring (L , name );
241
- return 1 ;
242
- }
243
-
244
-
245
- /*
246
- ** get (if 'get' is true) or set an upvalue from a closure
247
- */
248
- static int auxupvalue (lua_State * L , int get ) {
249
- const char * name ;
250
- int n = (int )luaL_checkinteger (L , 2 ); /* upvalue index */
251
- luaL_checktype (L , 1 , LUA_TFUNCTION ); /* closure */
252
- name = get ? lua_getupvalue (L , 1 , n ) : lua_setupvalue (L , 1 , n );
253
- if (name == NULL ) return 0 ;
254
- lua_pushstring (L , name );
255
- lua_insert (L , - (get + 1 )); /* no-op if get is false */
256
- return get + 1 ;
257
- }
258
-
259
-
260
- static int db_getupvalue (lua_State * L ) {
261
- return auxupvalue (L , 1 );
262
- }
263
-
264
-
265
- static int db_setupvalue (lua_State * L ) {
266
- luaL_checkany (L , 3 );
267
- return auxupvalue (L , 0 );
268
- }
269
-
270
-
271
- /*
272
- ** Check whether a given upvalue from a given closure exists and
273
- ** returns its index
274
- */
275
- static int checkupval (lua_State * L , int argf , int argnup ) {
276
- int nup = (int )luaL_checkinteger (L , argnup ); /* upvalue index */
277
- luaL_checktype (L , argf , LUA_TFUNCTION ); /* closure */
278
- luaL_argcheck (L , (lua_getupvalue (L , argf , nup ) != NULL ), argnup ,
279
- "invalid upvalue index" );
280
- return nup ;
281
- }
282
-
283
-
284
- static int db_upvalueid (lua_State * L ) {
285
- int n = checkupval (L , 1 , 2 );
286
- lua_pushlightuserdata (L , lua_upvalueid (L , 1 , n ));
287
- return 1 ;
288
- }
289
-
290
-
291
- static int db_upvaluejoin (lua_State * L ) {
292
- int n1 = checkupval (L , 1 , 2 );
293
- int n2 = checkupval (L , 3 , 4 );
294
- luaL_argcheck (L , !lua_iscfunction (L , 1 ), 1 , "Lua function expected" );
295
- luaL_argcheck (L , !lua_iscfunction (L , 3 ), 3 , "Lua function expected" );
296
- lua_upvaluejoin (L , 1 , n1 , 3 , n2 );
297
- return 0 ;
298
- }
299
-
300
-
301
150
/*
302
151
** Call hook function registered at hook table for the current
303
152
** thread (if there is one)
@@ -344,7 +193,7 @@ static char *unmakemask (int mask, char *smask) {
344
193
}
345
194
346
195
347
- static int db_sethook (lua_State * L ) {
196
+ extern int db_sethook (lua_State * L ) {
348
197
int arg , mask , count ;
349
198
lua_Hook func ;
350
199
lua_State * L1 = getthread (L , & arg );
@@ -376,7 +225,7 @@ static int db_sethook (lua_State *L) {
376
225
}
377
226
378
227
379
- static int db_gethook (lua_State * L ) {
228
+ extern int db_gethook (lua_State * L ) {
380
229
int arg ;
381
230
lua_State * L1 = getthread (L , & arg );
382
231
char buff [5 ];
@@ -397,60 +246,3 @@ static int db_gethook (lua_State *L) {
397
246
lua_pushinteger (L , lua_gethookcount (L1 )); /* 3rd result = count */
398
247
return 3 ;
399
248
}
400
-
401
-
402
- static int db_debug (lua_State * L ) {
403
- for (;;) {
404
- char buffer [250 ];
405
- lua_writestringerror ("%s" , "lua_debug> " );
406
- if (fgets (buffer , sizeof (buffer ), stdin ) == 0 ||
407
- strcmp (buffer , "cont\n" ) == 0 )
408
- return 0 ;
409
- if (luaL_loadbuffer (L , buffer , strlen (buffer ), "=(debug command)" ) ||
410
- lua_pcall (L , 0 , 0 , 0 ))
411
- lua_writestringerror ("%s\n" , lua_tostring (L , -1 ));
412
- lua_settop (L , 0 ); /* remove eventual returns */
413
- }
414
- }
415
-
416
-
417
- static int db_traceback (lua_State * L ) {
418
- int arg ;
419
- lua_State * L1 = getthread (L , & arg );
420
- const char * msg = lua_tostring (L , arg + 1 );
421
- if (msg == NULL && !lua_isnoneornil (L , arg + 1 )) /* non-string 'msg'? */
422
- lua_pushvalue (L , arg + 1 ); /* return it untouched */
423
- else {
424
- int level = (int )luaL_optinteger (L , arg + 2 , (L == L1 ) ? 1 : 0 );
425
- luaL_traceback (L , L1 , msg , level );
426
- }
427
- return 1 ;
428
- }
429
-
430
-
431
- static const luaL_Reg dblib [] = {
432
- {"debug" , db_debug },
433
- {"getuservalue" , db_getuservalue },
434
- {"gethook" , db_gethook },
435
- {"getinfo" , db_getinfo },
436
- {"getlocal" , db_getlocal },
437
- {"getregistry" , db_getregistry },
438
- {"getmetatable" , db_getmetatable },
439
- {"getupvalue" , db_getupvalue },
440
- {"upvaluejoin" , db_upvaluejoin },
441
- {"upvalueid" , db_upvalueid },
442
- {"setuservalue" , db_setuservalue },
443
- {"sethook" , db_sethook },
444
- {"setlocal" , db_setlocal },
445
- {"setmetatable" , db_setmetatable },
446
- {"setupvalue" , db_setupvalue },
447
- {"traceback" , db_traceback },
448
- {NULL , NULL }
449
- };
450
-
451
-
452
- LUAMOD_API int luaopen_debug (lua_State * L ) {
453
- luaL_newlib (L , dblib );
454
- return 1 ;
455
- }
456
-
0 commit comments