diff options
Diffstat (limited to '')
-rw-r--r-- | ClientHamr/GuiLua/test_c.c | 66 |
1 files changed, 7 insertions, 59 deletions
diff --git a/ClientHamr/GuiLua/test_c.c b/ClientHamr/GuiLua/test_c.c index 7a33570..37b5c76 100644 --- a/ClientHamr/GuiLua/test_c.c +++ b/ClientHamr/GuiLua/test_c.c | |||
@@ -10,8 +10,7 @@ http://lua-users.org/lists/lua-l/2008-01/msg00671.html | |||
10 | */ | 10 | */ |
11 | 11 | ||
12 | 12 | ||
13 | #include <lua.h> | 13 | #include "GuiLua.h" |
14 | #include <lauxlib.h> | ||
15 | 14 | ||
16 | 15 | ||
17 | static const char *ourName = "test_c"; | 16 | static const char *ourName = "test_c"; |
@@ -26,7 +25,6 @@ static int cfunc (lua_State *L) | |||
26 | return 0; | 25 | return 0; |
27 | } | 26 | } |
28 | 27 | ||
29 | |||
30 | /* local test_c = require 'test_c' | 28 | /* local test_c = require 'test_c' |
31 | 29 | ||
32 | Lua's require() function will strip any stuff from the front of the name | 30 | Lua's require() function will strip any stuff from the front of the name |
@@ -41,8 +39,6 @@ returned, but we want to do something different with skang. | |||
41 | */ | 39 | */ |
42 | int luaopen_test_c(lua_State *L) | 40 | int luaopen_test_c(lua_State *L) |
43 | { | 41 | { |
44 | lua_Number i; | ||
45 | |||
46 | // In theory, the only thing on the stack now is 'test_c' from the require() call. | 42 | // In theory, the only thing on the stack now is 'test_c' from the require() call. |
47 | 43 | ||
48 | // pseudo-indices, special tables that can be accessed like the stack - | 44 | // pseudo-indices, special tables that can be accessed like the stack - |
@@ -67,15 +63,7 @@ int luaopen_test_c(lua_State *L) | |||
67 | lua_getfield(L, LUA_REGISTRYINDEX, "skang"); | 63 | lua_getfield(L, LUA_REGISTRYINDEX, "skang"); |
68 | 64 | ||
69 | // local _M = skang.moduleBegin('test_c', nil, 'Copyright 2014 David Seikel', '0.1', '2014-03-27 03:57:00', nil, false) | 65 | // local _M = skang.moduleBegin('test_c', nil, 'Copyright 2014 David Seikel', '0.1', '2014-03-27 03:57:00', nil, false) |
70 | lua_getfield(L, skang, "moduleBegin"); | 66 | push_lua(L, "@ ( $ ~ $ $ $ ~ ! )", skang, "moduleBegin", ourName, "Copyright 2014 David Seikel", "0.1", "2014-03-27 03:57:00", 0, 1); |
71 | lua_pushstring(L, ourName); | ||
72 | lua_pushnil(L); // Author comes from copyright. | ||
73 | lua_pushstring(L, "Copyright 2014 David Seikel"); | ||
74 | lua_pushstring(L, "0.1"); | ||
75 | lua_pushstring(L, "2014-03-27 03:57:00"); | ||
76 | lua_pushnil(L); // No skin. | ||
77 | lua_pushboolean(L, 0); // We are not a Lua module. | ||
78 | lua_call(L, 7, 1); // call 'skang.moduleBegin' with 7 arguments and 1 result. | ||
79 | _M = lua_gettop(L); | 67 | _M = lua_gettop(L); |
80 | 68 | ||
81 | // Save this module in the C registry. | 69 | // Save this module in the C registry. |
@@ -84,59 +72,19 @@ int luaopen_test_c(lua_State *L) | |||
84 | 72 | ||
85 | // This uses function{} style. | 73 | // This uses function{} style. |
86 | // skang.thingasm{_M, 'cfooble,c', 'cfooble help text', 1, widget=\"'edit', 'The cfooble:', 1, 1, 10, 50\", required=true} | 74 | // skang.thingasm{_M, 'cfooble,c', 'cfooble help text', 1, widget=\"'edit', 'The cfooble:', 1, 1, 10, 50\", required=true} |
87 | lua_getfield(L, skang, "thingasm"); | 75 | push_lua(L, "@ ( { @ $ $ % $widget !required } )", skang, "thingasm", LUA_REGISTRYINDEX, ourName, "cfooble,c", "cfooble help text", 1, "'edit', 'The cfooble:', 1, 1, 10, 50", 1, 0); |
88 | i = 1; | ||
89 | lua_newtable(L); | ||
90 | lua_pushnumber(L, i++); | ||
91 | lua_getfield(L, LUA_REGISTRYINDEX, ourName); // Coz getfenv() can't find C environment. | ||
92 | lua_settable(L, -3); | ||
93 | |||
94 | lua_pushnumber(L, i++); | ||
95 | lua_pushstring(L, "cfooble,c"); | ||
96 | lua_settable(L, -3); | ||
97 | |||
98 | lua_pushnumber(L, i++); | ||
99 | lua_pushstring(L, "cfooble help text"); | ||
100 | lua_settable(L, -3); | ||
101 | |||
102 | lua_pushnumber(L, i++); | ||
103 | lua_pushnumber(L, 1); | ||
104 | lua_settable(L, -3); | ||
105 | |||
106 | lua_pushstring(L, "'edit', 'The cfooble:', 1, 1, 10, 50"); | ||
107 | lua_setfield(L, -2, "widget"); | ||
108 | lua_pushboolean(L, 1); // Is required. | ||
109 | lua_setfield(L, -2, "required"); | ||
110 | lua_call(L, 1, 0); | ||
111 | 76 | ||
112 | // skang.thing(_M, 'cbar', 'Help text', 'Default') | 77 | // skang.thing(_M, 'cbar', 'Help text', 'Default') |
113 | lua_getfield(L, skang, "thingasm"); | 78 | push_lua(L, "@ ( @ $ $ $ )", skang, "thingasm", LUA_REGISTRYINDEX, ourName, "cbar", "Help text", "Default", 0); |
114 | lua_getfield(L, LUA_REGISTRYINDEX, ourName); // Coz getfenv() can't find C environment. | ||
115 | lua_pushstring(L, "cbar"); | ||
116 | lua_pushstring(L, "Help text"); | ||
117 | lua_pushstring(L, "Default"); | ||
118 | lua_call(L, 4, 0); | ||
119 | 79 | ||
120 | // skang.thingasm(_M, 'cfoo') | 80 | // skang.thingasm(_M, 'cfoo') |
121 | lua_getfield(L, skang, "thingasm"); | 81 | push_lua(L, "@ ( @ $ )", skang, "thingasm", LUA_REGISTRYINDEX, ourName, "cfoo", 0); |
122 | lua_getfield(L, LUA_REGISTRYINDEX, ourName); // Coz getfenv() can't find C environment. | ||
123 | lua_pushstring(L, "cfoo"); | ||
124 | lua_call(L, 2, 0); | ||
125 | 82 | ||
126 | // skang.thingasm(_M, 'cfunc', 'cfunc does nothing really', cfunc, 'number,string') | 83 | // skang.thingasm(_M, 'cfunc', 'cfunc does nothing really', cfunc, 'number,string') |
127 | // push_lua(L, "@ @ $ $ & $", skang, "thingasm", LUA_REGISTRYINDEX, ourName, "cfunc", "cfunc does nothing really", cfunc, "number,string"); | 84 | push_lua(L, "@ ( @ $ $ & $ )", skang, "thingasm", LUA_REGISTRYINDEX, ourName, "cfunc", "cfunc does nothing really", cfunc, "number,string", 0); |
128 | lua_getfield(L, skang, "thingasm"); | ||
129 | lua_getfield(L, LUA_REGISTRYINDEX, ourName); // Coz getfenv() can't find C environment. | ||
130 | lua_pushstring(L, "cfunc"); | ||
131 | lua_pushstring(L, "cfunc does nothing really"); | ||
132 | lua_pushcfunction(L, cfunc); | ||
133 | lua_pushstring(L, "number,string"); | ||
134 | lua_call(L, 5, 0); | ||
135 | 85 | ||
136 | // skang.moduleEnd(_M) | 86 | // skang.moduleEnd(_M) |
137 | lua_getfield(L, skang, "moduleEnd"); | 87 | push_lua(L, "@ ( @ )", skang, "moduleEnd", LUA_REGISTRYINDEX, ourName, 0); |
138 | lua_getfield(L, LUA_REGISTRYINDEX, ourName); | ||
139 | lua_call(L, 1, 0); | ||
140 | 88 | ||
141 | return 1; | 89 | return 1; |
142 | } | 90 | } |