diff options
| author | lneto <lneto@NetBSD.org> | 2013-12-16 23:35:48 +0000 |
|---|---|---|
| committer | lneto <lneto@NetBSD.org> | 2013-12-16 23:35:48 +0000 |
| commit | 80c8ccad5707bb0709a3fb6263e6abe3e4f497ea (patch) | |
| tree | 787dd47a3d416d702638f987119740e76cd4fd39 /sys/modules | |
| parent | a761e7f1815d46fe235a5e6dd8c80bce8396c49f (diff) | |
using luaL_register() in luapmf
Diffstat (limited to 'sys/modules')
| -rw-r--r-- | sys/modules/luapmf/Makefile | 5 | ||||
| -rw-r--r-- | sys/modules/luapmf/luapmf.c | 23 |
2 files changed, 9 insertions, 19 deletions
diff --git a/sys/modules/luapmf/Makefile b/sys/modules/luapmf/Makefile index 52e7152a77f..28a88d7f6c8 100644 --- a/sys/modules/luapmf/Makefile +++ b/sys/modules/luapmf/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.1 2013/10/28 20:06:05 mbalmer Exp $ +# $NetBSD: Makefile,v 1.2 2013/12/16 23:35:48 lneto Exp $ .include "../Makefile.inc" @@ -6,6 +6,7 @@ KMOD= luapmf SRCS= luapmf.c CPPFLAGS+= -I${S}/../external/mit/lua/dist/src \ - -I${S}/modules/lua + -I${S}/modules/lua \ + -I${S}/sys .include <bsd.kmodule.mk> diff --git a/sys/modules/luapmf/luapmf.c b/sys/modules/luapmf/luapmf.c index e61dc7fe6e0..0e72bf699c3 100644 --- a/sys/modules/luapmf/luapmf.c +++ b/sys/modules/luapmf/luapmf.c @@ -1,4 +1,4 @@ -/* $NetBSD: luapmf.c,v 1.2 2013/10/29 09:18:45 mbalmer Exp $ */ +/* $NetBSD: luapmf.c,v 1.3 2013/12/16 23:35:48 lneto Exp $ */ /* * Copyright (c) 2011, 2013 Marc Balmer <mbalmer@NetBSD.org>. @@ -39,6 +39,7 @@ #include <sys/reboot.h> #include <lua.h> +#include <lauxlib.h> #ifdef _MODULE MODULE(MODULE_CLASS_MISC, luapmf, "lua"); @@ -80,29 +81,18 @@ get_platform(lua_State *L) } -struct pmf_reg { - const char *n; - int (*f)(lua_State *); -}; - static int luaopen_pmf(void *ls) { lua_State *L = (lua_State *)ls; - int n, nfunc; - struct pmf_reg pmf[] = { + const luaL_Reg pmf_lib[ ] = { { "system_shutdown", system_shutdown }, { "set_platform", set_platform }, - { "get_platform", get_platform } + { "get_platform", get_platform }, + { NULL, NULL } }; - nfunc = sizeof(pmf)/sizeof(pmf[1]); - - lua_createtable(L, nfunc, 0); - for (n = 0; n < nfunc; n++) { - lua_pushcfunction(L, pmf[n].f); - lua_setfield(L, -2, pmf[n].n); - } + luaL_register(L, "pmf", pmf_lib); /* some integer values */ lua_pushinteger(L, PMFE_DISPLAY_ON); @@ -152,7 +142,6 @@ luaopen_pmf(void *ls) lua_pushinteger(L, RB_USERCONF); lua_setfield(L, -2, "RB_USERCONF"); - lua_setglobal(L, "pmf"); return 1; } |
