aboutsummaryrefslogtreecommitdiff
path: root/stand/liblua
diff options
context:
space:
mode:
authorWarner Losh <imp@FreeBSD.org>2024-02-16 03:53:47 +0000
committerWarner Losh <imp@FreeBSD.org>2024-02-16 03:59:23 +0000
commit0921a771da8a9117edf26352a8a047bacbfcee45 (patch)
tree14344ee37d67db2797ed749896bf401ef98ef764 /stand/liblua
parent23d9b5c9febf4b02957d01bc46ee75530b0dcb4a (diff)
downloadsrc-0921a771da8a9117edf26352a8a047bacbfcee45.tar.gz
src-0921a771da8a9117edf26352a8a047bacbfcee45.zip
loader: Move to using linker sets to bring in optional bits
The graphics stuff is optional. When it is pulled into the system, we use a linker set to initialize the lua bindings for it now. Sponsored by: Netflix Reviewed by: kevans, jhb Differential Revision: https://reviews.freebsd.org/D43906
Diffstat (limited to 'stand/liblua')
-rw-r--r--stand/liblua/gfx_utils.c27
-rw-r--r--stand/liblua/lutils.h9
2 files changed, 36 insertions, 0 deletions
diff --git a/stand/liblua/gfx_utils.c b/stand/liblua/gfx_utils.c
index d2d22738c929..8d2aaacbd688 100644
--- a/stand/liblua/gfx_utils.c
+++ b/stand/liblua/gfx_utils.c
@@ -245,3 +245,30 @@ void
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
index c1fd6af496e5..522abfd3d0d4 100644
--- a/stand/liblua/lutils.h
+++ b/stand/liblua/lutils.h
@@ -30,3 +30,12 @@ int luaopen_gfx(lua_State *);
int luaopen_loader(lua_State *);
int luaopen_io(lua_State *);
int luaopen_pager(lua_State *);
+
+#include <sys/linker_set.h>
+
+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);