【发布时间】:2018-03-22 06:34:47
【问题描述】:
我正在尝试使用 C API 在 Lua 中包装 ncurses。我正在使用stdscr 指针:在调用initscr 之前这是NULL,并且通过我的绑定设计从Lua 调用initscr。所以在驱动函数中我这样做:
// 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,所以它本质上是在运行 keypad(NULL, true); 的 c 等效项
我的问题是,创建库后如何在 Lua 中修改库值?
【问题讨论】: