summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThijs <thijs@thijsschreijer.nl>2024-05-23 08:51:31 +0200
committerThijs <thijs@thijsschreijer.nl>2024-05-23 09:05:07 +0200
commit9f6958c429627190917f742f46a3ae60ed6e7ca0 (patch)
tree9c2e6fb0a4bb952de1d66a851bbfcb34cfddf4c1
parent7e9447c98588730738724176d9acc595be6299e6 (diff)
downloadluasystem-9f6958c429627190917f742f46a3ae60ed6e7ca0.zip
Windows fixes, some manual tests
-rw-r--r--spec/04-term_spec.lua12
-rw-r--r--src/compat.c16
-rw-r--r--src/compat.h1
-rw-r--r--src/term.c12
4 files changed, 31 insertions, 10 deletions
diff --git a/spec/04-term_spec.lua b/spec/04-term_spec.lua
index 50fba45..3711900 100644
--- a/spec/04-term_spec.lua
+++ b/spec/04-term_spec.lua
@@ -208,7 +208,7 @@ describe("Terminal:", function()
describe("tcsetattr()", function()
- nix_it("sets the terminal flags, if called with flags", function()
+ pending("sets the terminal flags, if called with flags", function()
assert.equal(true, false)
end)
@@ -222,14 +222,14 @@ describe("Terminal:", function()
it("returns an error if called with an invalid first argument", function()
assert.has.error(function()
- system.tcsetattr("invalid")
+ system.tcsetattr("invalid", system.TCSANOW, {})
end, "bad argument #1 to 'tcsetattr' (FILE* expected, got string)")
end)
it("returns an error if called with an invalid second argument", function()
assert.has.error(function()
- system.tcsetattr(io.stdin, "invalid")
+ system.tcsetattr(io.stdin, "invalid", {})
end, "bad argument #2 to 'tcsetattr' (number expected, got string)")
end)
@@ -241,7 +241,7 @@ describe("Terminal:", function()
end)
- it("returns an error if iflag is not a bitflags object", function()
+ it("returns an error if iflag is not a bitflags object #manual", function()
local flags = assert(system.tcgetattr(io.stdin))
flags.iflag = 0
assert.has.error(function()
@@ -250,7 +250,7 @@ describe("Terminal:", function()
end)
- it("returns an error if oflag is not a bitflags object", function()
+ it("returns an error if oflag is not a bitflags object #manual", function()
local flags = assert(system.tcgetattr(io.stdin))
flags.oflag = 0
assert.has.error(function()
@@ -259,7 +259,7 @@ describe("Terminal:", function()
end)
- it("returns an error if lflag is not a bitflags object", function()
+ it("returns an error if lflag is not a bitflags object #manual", function()
local flags = assert(system.tcgetattr(io.stdin))
flags.lflag = 0
assert.has.error(function()
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);