diff options
| author | Thijs <thijs@thijsschreijer.nl> | 2024-05-23 08:51:31 +0200 |
|---|---|---|
| committer | Thijs <thijs@thijsschreijer.nl> | 2024-05-23 09:05:07 +0200 |
| commit | 9f6958c429627190917f742f46a3ae60ed6e7ca0 (patch) | |
| tree | 9c2e6fb0a4bb952de1d66a851bbfcb34cfddf4c1 | |
| parent | 7e9447c98588730738724176d9acc595be6299e6 (diff) | |
| download | luasystem-9f6958c429627190917f742f46a3ae60ed6e7ca0.tar.gz luasystem-9f6958c429627190917f742f46a3ae60ed6e7ca0.tar.bz2 luasystem-9f6958c429627190917f742f46a3ae60ed6e7ca0.zip | |
Windows fixes, some manual tests
| -rw-r--r-- | spec/04-term_spec.lua | 12 | ||||
| -rw-r--r-- | src/compat.c | 16 | ||||
| -rw-r--r-- | src/compat.h | 1 | ||||
| -rw-r--r-- | src/term.c | 12 |
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() | |||
| 208 | 208 | ||
| 209 | describe("tcsetattr()", function() | 209 | describe("tcsetattr()", function() |
| 210 | 210 | ||
| 211 | nix_it("sets the terminal flags, if called with flags", function() | 211 | pending("sets the terminal flags, if called with flags", function() |
| 212 | assert.equal(true, false) | 212 | assert.equal(true, false) |
| 213 | end) | 213 | end) |
| 214 | 214 | ||
| @@ -222,14 +222,14 @@ describe("Terminal:", function() | |||
| 222 | 222 | ||
| 223 | it("returns an error if called with an invalid first argument", function() | 223 | it("returns an error if called with an invalid first argument", function() |
| 224 | assert.has.error(function() | 224 | assert.has.error(function() |
| 225 | system.tcsetattr("invalid") | 225 | system.tcsetattr("invalid", system.TCSANOW, {}) |
| 226 | end, "bad argument #1 to 'tcsetattr' (FILE* expected, got string)") | 226 | end, "bad argument #1 to 'tcsetattr' (FILE* expected, got string)") |
| 227 | end) | 227 | end) |
| 228 | 228 | ||
| 229 | 229 | ||
| 230 | it("returns an error if called with an invalid second argument", function() | 230 | it("returns an error if called with an invalid second argument", function() |
| 231 | assert.has.error(function() | 231 | assert.has.error(function() |
| 232 | system.tcsetattr(io.stdin, "invalid") | 232 | system.tcsetattr(io.stdin, "invalid", {}) |
| 233 | end, "bad argument #2 to 'tcsetattr' (number expected, got string)") | 233 | end, "bad argument #2 to 'tcsetattr' (number expected, got string)") |
| 234 | end) | 234 | end) |
| 235 | 235 | ||
| @@ -241,7 +241,7 @@ describe("Terminal:", function() | |||
| 241 | end) | 241 | end) |
| 242 | 242 | ||
| 243 | 243 | ||
| 244 | it("returns an error if iflag is not a bitflags object", function() | 244 | it("returns an error if iflag is not a bitflags object #manual", function() |
| 245 | local flags = assert(system.tcgetattr(io.stdin)) | 245 | local flags = assert(system.tcgetattr(io.stdin)) |
| 246 | flags.iflag = 0 | 246 | flags.iflag = 0 |
| 247 | assert.has.error(function() | 247 | assert.has.error(function() |
| @@ -250,7 +250,7 @@ describe("Terminal:", function() | |||
| 250 | end) | 250 | end) |
| 251 | 251 | ||
| 252 | 252 | ||
| 253 | it("returns an error if oflag is not a bitflags object", function() | 253 | it("returns an error if oflag is not a bitflags object #manual", function() |
| 254 | local flags = assert(system.tcgetattr(io.stdin)) | 254 | local flags = assert(system.tcgetattr(io.stdin)) |
| 255 | flags.oflag = 0 | 255 | flags.oflag = 0 |
| 256 | assert.has.error(function() | 256 | assert.has.error(function() |
| @@ -259,7 +259,7 @@ describe("Terminal:", function() | |||
| 259 | end) | 259 | end) |
| 260 | 260 | ||
| 261 | 261 | ||
| 262 | it("returns an error if lflag is not a bitflags object", function() | 262 | it("returns an error if lflag is not a bitflags object #manual", function() |
| 263 | local flags = assert(system.tcgetattr(io.stdin)) | 263 | local flags = assert(system.tcgetattr(io.stdin)) |
| 264 | flags.lflag = 0 | 264 | flags.lflag = 0 |
| 265 | assert.has.error(function() | 265 | 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) { | |||
| 14 | } | 14 | } |
| 15 | lua_pop(L, nup); /* remove upvalues */ | 15 | lua_pop(L, nup); /* remove upvalues */ |
| 16 | } | 16 | } |
| 17 | |||
| 18 | void *luaL_testudata(lua_State *L, int ud, const char *tname) { | ||
| 19 | void *p = lua_touserdata(L, ud); | ||
| 20 | if (p != NULL) { /* Check for userdata */ | ||
| 21 | if (lua_getmetatable(L, ud)) { /* Does it have a metatable? */ | ||
| 22 | lua_getfield(L, LUA_REGISTRYINDEX, tname); /* Get metatable we're looking for */ | ||
| 23 | if (lua_rawequal(L, -1, -2)) { /* Compare metatables */ | ||
| 24 | lua_pop(L, 2); /* Remove metatables from stack */ | ||
| 25 | return p; | ||
| 26 | } | ||
| 27 | lua_pop(L, 2); /* Remove metatables from stack */ | ||
| 28 | } | ||
| 29 | } | ||
| 30 | return NULL; /* Return NULL if check fails */ | ||
| 31 | } | ||
| 32 | |||
| 17 | #endif | 33 | #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 @@ | |||
| 6 | 6 | ||
| 7 | #if LUA_VERSION_NUM == 501 | 7 | #if LUA_VERSION_NUM == 501 |
| 8 | void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup); | 8 | void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup); |
| 9 | void *luaL_testudata(lua_State *L, int ud, const char *tname); | ||
| 9 | #endif | 10 | #endif |
| 10 | 11 | ||
| 11 | 12 | ||
| @@ -493,6 +493,9 @@ static int lst_tcgetattr(lua_State *L) | |||
| 493 | lua_setfield(L, -2, "cc"); | 493 | lua_setfield(L, -2, "cc"); |
| 494 | 494 | ||
| 495 | #else | 495 | #else |
| 496 | lua_settop(L, 1); // remove all but file handle | ||
| 497 | get_console_handle(L, 1); //check args | ||
| 498 | |||
| 496 | lua_newtable(L); | 499 | lua_newtable(L); |
| 497 | lsbf_pushbitflags(L, 0); | 500 | lsbf_pushbitflags(L, 0); |
| 498 | lua_setfield(L, -2, "iflag"); | 501 | lua_setfield(L, -2, "iflag"); |
| @@ -584,11 +587,12 @@ static int lst_tcsetattr(lua_State *L) | |||
| 584 | 587 | ||
| 585 | #else | 588 | #else |
| 586 | // Windows does not have a tcsetattr function, but we check arguments anyway | 589 | // Windows does not have a tcsetattr function, but we check arguments anyway |
| 587 | get_console_handle(L, 1); // to validate args | ||
| 588 | luaL_checkinteger(L, 2); | 590 | luaL_checkinteger(L, 2); |
| 589 | lsbf_checkbitflagsfield(L, 3, "iflag", t.c_iflag); | 591 | lsbf_checkbitflagsfield(L, 3, "iflag", 0); |
| 590 | lsbf_checkbitflagsfield(L, 3, "oflag", t.c_iflag); | 592 | lsbf_checkbitflagsfield(L, 3, "oflag", 0); |
| 591 | lsbf_checkbitflagsfield(L, 3, "lflag", t.c_iflag); | 593 | lsbf_checkbitflagsfield(L, 3, "lflag", 0); |
| 594 | lua_settop(L, 1); // remove all but file handle | ||
| 595 | get_console_handle(L, 1); | ||
| 592 | #endif | 596 | #endif |
| 593 | 597 | ||
| 594 | lua_pushboolean(L, 1); | 598 | lua_pushboolean(L, 1); |
