Skip to content

Commit a54a3c0

Browse files
committed
fixed support for strings, math, table functions.
1 parent fb9b741 commit a54a3c0

File tree

3 files changed

+28
-41
lines changed

3 files changed

+28
-41
lines changed

lua_main.c

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -76,73 +76,61 @@ static const struct luaL_reg fslib[] = {
7676
{NULL, NULL},
7777
};
7878

79-
static apr_status_t lua_wapr_register(lua_State * L, apr_pool_t * root_pool)
79+
static void lua_lkl_register(lua_State * L)
8080
{
81-
gp = root_pool;
8281
lua_register(L, "stat", luk_stat);
8382
luaL_register (L, "lkl", fslib);
84-
return APR_SUCCESS;
8583
}
86-
///=========================================================
87-
88-
89-
90-
91-
92-
93-
94-
95-
96-
9784

9885

9986

10087

10188

102-
103-
104-
105-
///==============================================================
106-
107-
static const luaL_reg lualibs[] =
89+
typedef void (*my_lua_registerer_t) (lua_State *L);
90+
static const my_lua_registerer_t lualibs[] =
10891
{
109-
{ "base", luaopen_base },
110-
{ "lkl", lua_wapr_register},
111-
{ NULL, NULL }
92+
luaL_openlibs,
93+
luaopen_wapr,
94+
lua_lkl_register
11295
};
11396

11497
/* A function to open up all the Lua libraries we've declared above. */
11598
static void openlualibs(lua_State *l)
11699
{
117-
const luaL_reg *lib;
118-
119-
for (lib = lualibs; lib->func != NULL; lib++)
100+
int i;
101+
for(i = 0; i < sizeof(lualibs)/sizeof(my_lua_registerer_t); i++)
120102
{
121-
lib->func(l);
122-
lua_settop(l, 0);
103+
lualibs[i](l);
104+
lua_settop(l, 0);
123105
}
124106
}
125107

126-
static void lua_run_script(lua_State*L, const char *filename) {
127-
#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >=501
128-
(void)luaL_dofile(L, filename);
129-
#else
130-
(void)lua_dofile(L, filename);
131-
#endif
108+
static void lua_run_script(lua_State*L, const char *filename)
109+
{
110+
int s = luaL_loadfile(L, filename);
111+
if(0 == s)
112+
{
113+
s = lua_pcall(L, 0, LUA_MULTRET, 0);
114+
}
115+
if (0 != s)
116+
{
117+
fprintf(stderr, "LUA Error: %s\n", lua_tostring(L, -1));
118+
lua_pop(L, 1); // remove error message
119+
}
132120
}
133121

134122

135123
apr_status_t lua_lkl_main(const char * script_file, apr_pool_t * root_pool)
136124
{
125+
gp = root_pool;
137126
/* initialize Lua */
138127
L = lua_open();
128+
if(NULL == L)
129+
return -1;
139130

140-
/* load Lua base libraries */
131+
/* load Lua base libraries & our extensions */
141132
openlualibs(L);
142133

143-
/* register our functions */
144-
luaopen_wapr(L);
145-
146134
/* run the script */
147135
lua_run_script(L, script_file);
148136

lua_wapr.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,9 +605,8 @@ static const struct luaL_reg fslib[] = {
605605
{NULL, NULL},
606606
};
607607

608-
int luaopen_wapr (lua_State *L) {
608+
void luaopen_wapr (lua_State *L) {
609609
dir_create_meta (L);
610610
luaL_register (L, "apr", fslib);
611611
set_info (L);
612-
return 1;
613612
}

lua_wapr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
#define chdir_error strerror(errno)
1414
#endif
1515

16-
int luaopen_wapr (lua_State *L);
16+
void luaopen_wapr (lua_State *L);

0 commit comments

Comments
 (0)