-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathc_test.c
More file actions
53 lines (38 loc) · 1 KB
/
c_test.c
File metadata and controls
53 lines (38 loc) · 1 KB
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
#include <stdio.h>
#include <stack_debug.h>
#define LOG_ERR 0
#define LOG_NORMAL 1
#define LOG_DEBUG 2
#define LOG_LEVEL LOG_DEBUG
#define _log(lvl, fmt, ...)\
if(lvl >= LOG_LEVEL){\
fprintf (stdout, fmt, __VA_ARGS__);\
}
#define Debug(fmt, ...) _log(LOG_DEBUG, fmt, __VA_ARGS__);
/*copy a table of the index on the stack */
void t_shallow_copy(lua_State* L, int index) {
lua_newtable(L);
lua_pushnil(L);
while(lua_next(L, index) != 0) {
lua_pushvalue(L, -2);
lua_insert(L, -2);
lua_settable(L, -4);
}
}
int main (void) {
lua_State *L = lua_open();
lua_newtable(L);
lua_pushstring(L, "key-a");
lua_pushstring(L, "I-am-value-9");
lua_settable(L, -3);
t_shallow_copy(L, 1);
lua_pushstring(L, "key-a");
lua_pushstring(L, "I-am-value-8888");
lua_settable(L, -3);
stackDump(L, "table");
PrintTable(L);
lua_pop(L, 1);
PrintTable(L);
Debug("Imadfdfa[%d] [%s]\n",1231, "dadd");
return 0;
}