diff --git a/stand/common/interp_lua.c b/stand/common/interp_lua.c --- a/stand/common/interp_lua.c +++ b/stand/common/interp_lua.c @@ -97,31 +97,6 @@ {NULL, NULL} }; -static void -interp_init_md(lua_State *L) -{ - luaL_requiref(L, "gfx", luaopen_gfx, 1); - lua_pop(L, 1); /* Remove lib */ - - /* - * Add in the comparability references in the loader table. Doing it with - * a pseudo-embedded script is easier than the raw calls. - */ - if (luaL_dostring(L, - "loader.fb_bezier = gfx.fb_bezier\n" - "loader.fb_drawrect = gfx.fb_drawrect\n" - "loader.fb_line = gfx.fb_line\n" - "loader.fb_putimage = gfx.fb_putimage\n" - "loader.fb_setpixel = gfx.fb_setpixel\n" - "loader.term_drawrect = gfx.term_drawrect\n" - "loader.term_putimage = gfx.term_putimage") != 0) { - lua_pop(L, 1); - const char *errstr = lua_tostring(L, -1); - errstr = errstr == NULL ? "unknown" : errstr; - printf("Error adding compat loader bindings: %s.\n", errstr); - } -} - void interp_init(void) { @@ -129,6 +104,7 @@ struct interp_lua_softc *softc = &lua_softc; const char *filename; const luaL_Reg *lib; + lua_init_md_t **fnpp; TSENTER(); @@ -148,7 +124,8 @@ lua_pop(luap, 1); /* remove lib */ } - interp_init_md(luap); + LUA_FOREACH_SET(fnpp) + (*fnpp)(luap); filename = getenv("loader_lua"); if (filename == NULL) diff --git a/stand/liblua/gfx_utils.c b/stand/liblua/gfx_utils.c --- a/stand/liblua/gfx_utils.c +++ b/stand/liblua/gfx_utils.c @@ -245,3 +245,30 @@ gfx_interp_md(void) { } + +static void +gfx_init_md(lua_State *L) +{ + luaL_requiref(L, "gfx", luaopen_gfx, 1); + lua_pop(L, 1); /* Remove lib */ + + /* + * Add in the compatibility references in the loader table. Doing it with + * a pseudo-embedded script is easier than the raw calls. + */ + if (luaL_dostring(L, + "loader.fb_bezier = gfx.fb_bezier\n" + "loader.fb_drawrect = gfx.fb_drawrect\n" + "loader.fb_line = gfx.fb_line\n" + "loader.fb_putimage = gfx.fb_putimage\n" + "loader.fb_setpixel = gfx.fb_setpixel\n" + "loader.term_drawrect = gfx.term_drawrect\n" + "loader.term_putimage = gfx.term_putimage") != 0) { + lua_pop(L, 1); + const char *errstr = lua_tostring(L, -1); + errstr = errstr == NULL ? "unknown" : errstr; + printf("Error adding compat loader bindings: %s.\n", errstr); + } +} + +LUA_COMPILE_SET(gfx_init_md); diff --git a/stand/liblua/lutils.h b/stand/liblua/lutils.h --- a/stand/liblua/lutils.h +++ b/stand/liblua/lutils.h @@ -30,3 +30,12 @@ int luaopen_loader(lua_State *); int luaopen_io(lua_State *); int luaopen_pager(lua_State *); + +#include + +typedef void lua_init_md_t(lua_State *); +#define LUA_COMPILE_SET(func) \ + DATA_SET(Xficl_compile_set, func) /* XXX linker set know by ldscrips */ +#define LUA_FOREACH_SET(s) \ + SET_FOREACH((s), Xficl_compile_set) +SET_DECLARE(Xficl_compile_set, lua_init_md_t);