using luaL_register() in luapmf
This commit is contained in:
parent
a88c18e5e2
commit
b716fbc627
|
@ -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>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue