Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/modules/luapmf using luaL_register() in luapmf



details:   https://anonhg.NetBSD.org/src/rev/3ac18cad0cdb
branches:  trunk
changeset: 792031:3ac18cad0cdb
user:      lneto <lneto%NetBSD.org@localhost>
date:      Mon Dec 16 23:35:48 2013 +0000

description:
using luaL_register() in luapmf

diffstat:

 sys/modules/luapmf/Makefile |   5 +++--
 sys/modules/luapmf/luapmf.c |  23 ++++++-----------------
 2 files changed, 9 insertions(+), 19 deletions(-)

diffs (77 lines):

diff -r 4f4e852c9c79 -r 3ac18cad0cdb sys/modules/luapmf/Makefile
--- a/sys/modules/luapmf/Makefile       Mon Dec 16 23:27:33 2013 +0000
+++ b/sys/modules/luapmf/Makefile       Mon Dec 16 23:35:48 2013 +0000
@@ -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 @@
 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 -r 4f4e852c9c79 -r 3ac18cad0cdb sys/modules/luapmf/luapmf.c
--- a/sys/modules/luapmf/luapmf.c       Mon Dec 16 23:27:33 2013 +0000
+++ b/sys/modules/luapmf/luapmf.c       Mon Dec 16 23:35:48 2013 +0000
@@ -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@localhost>.
@@ -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 @@
 
 }
 
-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 @@
        lua_pushinteger(L, RB_USERCONF);
        lua_setfield(L, -2, "RB_USERCONF");
 
-       lua_setglobal(L, "pmf");
        return 1;
 }
 



Home | Main Index | Thread Index | Old Index