Skip to content

Commit

Permalink
Windows fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tieske committed May 23, 2024
1 parent 7e9447c commit 4f4ed54
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
16 changes: 16 additions & 0 deletions src/compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions src/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
12 changes: 8 additions & 4 deletions src/term.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 4f4ed54

Please sign in to comment.