From 4f4ed54d64c653f92c997ff932ada2abfa3b5cb3 Mon Sep 17 00:00:00 2001 From: Thijs Date: Thu, 23 May 2024 08:51:31 +0200 Subject: [PATCH] Windows fixes --- src/compat.c | 16 ++++++++++++++++ src/compat.h | 1 + src/term.c | 12 ++++++++---- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/compat.c b/src/compat.c index 6f98854..2d2bec9 100644 --- a/src/compat.c +++ b/src/compat.c @@ -14,4 +14,20 @@ void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup) { } lua_pop(L, nup); /* remove upvalues */ } + +void *luaL_testudata(lua_State *L, int ud, const char *tname) { + void *p = lua_touserdata(L, ud); + if (p != NULL) { /* Check for userdata */ + if (lua_getmetatable(L, ud)) { /* Does it have a metatable? */ + lua_getfield(L, LUA_REGISTRYINDEX, tname); /* Get metatable we're looking for */ + if (lua_rawequal(L, -1, -2)) { /* Compare metatables */ + lua_pop(L, 2); /* Remove metatables from stack */ + return p; + } + lua_pop(L, 2); /* Remove metatables from stack */ + } + } + return NULL; /* Return NULL if check fails */ +} + #endif diff --git a/src/compat.h b/src/compat.h index 7a1fcee..2033aa3 100644 --- a/src/compat.h +++ b/src/compat.h @@ -6,6 +6,7 @@ #if LUA_VERSION_NUM == 501 void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup); +void *luaL_testudata(lua_State *L, int ud, const char *tname); #endif diff --git a/src/term.c b/src/term.c index c0699f9..99d3b2b 100644 --- a/src/term.c +++ b/src/term.c @@ -493,6 +493,9 @@ static int lst_tcgetattr(lua_State *L) lua_setfield(L, -2, "cc"); #else + lua_settop(L, 1); // remove all but file handle + get_console_handle(L, 1); //check args + lua_newtable(L); lsbf_pushbitflags(L, 0); lua_setfield(L, -2, "iflag"); @@ -584,11 +587,12 @@ static int lst_tcsetattr(lua_State *L) #else // Windows does not have a tcsetattr function, but we check arguments anyway - get_console_handle(L, 1); // to validate args luaL_checkinteger(L, 2); - lsbf_checkbitflagsfield(L, 3, "iflag", t.c_iflag); - lsbf_checkbitflagsfield(L, 3, "oflag", t.c_iflag); - lsbf_checkbitflagsfield(L, 3, "lflag", t.c_iflag); + lsbf_checkbitflagsfield(L, 3, "iflag", 0); + lsbf_checkbitflagsfield(L, 3, "oflag", 0); + lsbf_checkbitflagsfield(L, 3, "lflag", 0); + lua_settop(L, 1); // remove all but file handle + get_console_handle(L, 1); #endif lua_pushboolean(L, 1);