我正在尝试使用 C API 在 Lua 中包装 ncurses。我正在使用stdscr
指针:在initscr
调用之前这是 NULL,并且initscr
是通过我的绑定设计从 Lua 调用的。所以在驱动程序函数中我这样做:
// Driver function
LUALIB_API int luaopen_liblncurses(lua_State* L){
luaL_newlib(L, lncurseslib);
// This will start off as NULL
lua_pushlightuserdata(L, stdscr);
lua_setfield(L, -2, "stdscr");
lua_pushstring(L, VERSION);
lua_setglobal(L, "_LNCURSES_VERSION");
return 1;
}
这按预期工作。当我需要修改stdscr
. initscr
像这样绑定:
/*
** Put the terminal in curses mode
*/
static int lncurses_initscr(lua_State* L){
initscr();
return 0;
}
我需要修改stdscr
库中的不再为空。Lua 端的示例代码:
lncurses = require("liblncurses");
lncurses.initscr();
lncurses.keypad(lncurses.stdscr, true);
lncurses.getch();
lncurses.endwin();
但是,lncurses.stdscr
是 NULL,所以它本质上是在运行 c 等价于keypad(NULL, true);
我的问题是,创建库后如何在 Lua 中修改库值?