diff options
author | David Walter Seikel | 2014-04-17 15:05:12 +1000 |
---|---|---|
committer | David Walter Seikel | 2014-04-17 15:05:12 +1000 |
commit | 71c57cffa872a42759b84011c6e0f501c13f2e10 (patch) | |
tree | 71f328a942468398baec0bd830847d3a7fd0b766 /ClientHamr/GuiLua | |
parent | whitespace-- (diff) | |
download | SledjHamr-71c57cffa872a42759b84011c6e0f501c13f2e10.zip SledjHamr-71c57cffa872a42759b84011c6e0f501c13f2e10.tar.gz SledjHamr-71c57cffa872a42759b84011c6e0f501c13f2e10.tar.bz2 SledjHamr-71c57cffa872a42759b84011c6e0f501c13f2e10.tar.xz |
Fix the stack usage of test_c.
Diffstat (limited to '')
-rw-r--r-- | ClientHamr/GuiLua/test_c.c | 52 |
1 files changed, 5 insertions, 47 deletions
diff --git a/ClientHamr/GuiLua/test_c.c b/ClientHamr/GuiLua/test_c.c index ae21139..7a33570 100644 --- a/ClientHamr/GuiLua/test_c.c +++ b/ClientHamr/GuiLua/test_c.c | |||
@@ -27,28 +27,6 @@ static int cfunc (lua_State *L) | |||
27 | } | 27 | } |
28 | 28 | ||
29 | 29 | ||
30 | |||
31 | static void dumpStack(lua_State *L, int i) | ||
32 | { | ||
33 | int type = lua_type(L, i); | ||
34 | |||
35 | switch (type) | ||
36 | { | ||
37 | case LUA_TNONE : printf("Stack %d is empty\n", i); break; | ||
38 | case LUA_TNIL : printf("Stack %d is a nil\n", i); break; | ||
39 | case LUA_TBOOLEAN : printf("Stack %d is a boolean\n", i); break; | ||
40 | case LUA_TNUMBER : printf("Stack %d is a number\n", i); break; | ||
41 | case LUA_TSTRING : printf("Stack %d is a string - %s\n", i, lua_tostring(L, i)); break; | ||
42 | case LUA_TFUNCTION : printf("Stack %d is a function\n", i); break; | ||
43 | case LUA_TTHREAD : printf("Stack %d is a thread\n", i); break; | ||
44 | case LUA_TTABLE : printf("Stack %d is a table\n", i); break; | ||
45 | case LUA_TUSERDATA : printf("Stack %d is a userdata\n", i); break; | ||
46 | case LUA_TLIGHTUSERDATA : printf("Stack %d is a light userdata\n", i); break; | ||
47 | default : printf("Stack %d is unknown\n", i); break; | ||
48 | } | ||
49 | } | ||
50 | |||
51 | |||
52 | /* local test_c = require 'test_c' | 30 | /* local test_c = require 'test_c' |
53 | 31 | ||
54 | Lua's require() function will strip any stuff from the front of the name | 32 | Lua's require() function will strip any stuff from the front of the name |
@@ -84,7 +62,9 @@ int luaopen_test_c(lua_State *L) | |||
84 | lua_pushstring(L, "skang"); | 62 | lua_pushstring(L, "skang"); |
85 | lua_call(L, 1, 1); | 63 | lua_call(L, 1, 1); |
86 | skang = lua_gettop(L); | 64 | skang = lua_gettop(L); |
87 | // dumpStack(L, skang); | 65 | |
66 | lua_setfield(L, LUA_REGISTRYINDEX, "skang"); | ||
67 | lua_getfield(L, LUA_REGISTRYINDEX, "skang"); | ||
88 | 68 | ||
89 | // local _M = skang.moduleBegin('test_c', nil, 'Copyright 2014 David Seikel', '0.1', '2014-03-27 03:57:00', nil, false) | 69 | // local _M = skang.moduleBegin('test_c', nil, 'Copyright 2014 David Seikel', '0.1', '2014-03-27 03:57:00', nil, false) |
90 | lua_getfield(L, skang, "moduleBegin"); | 70 | lua_getfield(L, skang, "moduleBegin"); |
@@ -97,24 +77,10 @@ int luaopen_test_c(lua_State *L) | |||
97 | lua_pushboolean(L, 0); // We are not a Lua module. | 77 | lua_pushboolean(L, 0); // We are not a Lua module. |
98 | lua_call(L, 7, 1); // call 'skang.moduleBegin' with 7 arguments and 1 result. | 78 | lua_call(L, 7, 1); // call 'skang.moduleBegin' with 7 arguments and 1 result. |
99 | _M = lua_gettop(L); | 79 | _M = lua_gettop(L); |
100 | // dumpStack(L, _M); | ||
101 | |||
102 | // At this point the stack should be - 'test_c', skang, _M. Let's test that. | ||
103 | /* | ||
104 | int top = 0, j; | ||
105 | |||
106 | top = lua_gettop(L); | ||
107 | printf("MODULE test_c has %d stack items.\n", top); | ||
108 | for (j = 1; j <= top; j++) | ||
109 | dumpStack(L, j); | ||
110 | */ | ||
111 | 80 | ||
112 | // Save this module in the C registry. | 81 | // Save this module in the C registry. |
113 | lua_setfield(L, LUA_REGISTRYINDEX, ourName); | 82 | lua_setfield(L, LUA_REGISTRYINDEX, ourName); |
114 | 83 | lua_getfield(L, LUA_REGISTRYINDEX, ourName); | |
115 | // TODO - This is too verbose. I've had an idea for writing some sort of generic wrapper, though others have done the same. | ||
116 | // http://www.lua.org/pil/25.3.html seems the most reasonable of the examples I've found. | ||
117 | // On the other hand, the generic argument pulling / pushing stuff I did for edje_lua2 gets us half way there. | ||
118 | 84 | ||
119 | // This uses function{} style. | 85 | // This uses function{} style. |
120 | // skang.thingasm{_M, 'cfooble,c', 'cfooble help text', 1, widget=\"'edit', 'The cfooble:', 1, 1, 10, 50\", required=true} | 86 | // skang.thingasm{_M, 'cfooble,c', 'cfooble help text', 1, widget=\"'edit', 'The cfooble:', 1, 1, 10, 50\", required=true} |
@@ -170,15 +136,7 @@ int luaopen_test_c(lua_State *L) | |||
170 | // skang.moduleEnd(_M) | 136 | // skang.moduleEnd(_M) |
171 | lua_getfield(L, skang, "moduleEnd"); | 137 | lua_getfield(L, skang, "moduleEnd"); |
172 | lua_getfield(L, LUA_REGISTRYINDEX, ourName); | 138 | lua_getfield(L, LUA_REGISTRYINDEX, ourName); |
173 | // TODO - This should be (L, 1, 0), but that makes test.lua fail, claiming that none of the Things got added. WTF? | 139 | lua_call(L, 1, 0); |
174 | lua_call(L, 1, 1); | ||
175 | |||
176 | int top = 0, j; | ||
177 | |||
178 | top = lua_gettop(L); | ||
179 | printf("MODULE test_c has %d stack items.\n", top); | ||
180 | for (j = 1; j <= top; j++) | ||
181 | dumpStack(L, j); | ||
182 | 140 | ||
183 | return 1; | 141 | return 1; |
184 | } | 142 | } |