From c325be435c64be57cf2210fa6936af0d425d0ce0 Mon Sep 17 00:00:00 2001 From: Philipp Janda Date: Fri, 27 Jul 2018 07:35:24 +0200 Subject: Add an implementation of `lua_getextraspace()`. --- tests/test.lua | 19 +++++++++++++++---- tests/testmod.c | 16 ++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/test.lua b/tests/test.lua index c2c0abf..9bb08da 100755 --- a/tests/test.lua +++ b/tests/test.lua @@ -664,14 +664,12 @@ print("isinteger", mod.isinteger(12.3)) print("isinteger", mod.isinteger(math.huge)) print("isinteger", mod.isinteger(math.sqrt(-1))) - ___'' print("rotate", mod.rotate(1, 1, 2, 3, 4, 5, 6)) print("rotate", mod.rotate(-1, 1, 2, 3, 4, 5, 6)) print("rotate", mod.rotate(4, 1, 2, 3, 4, 5, 6)) print("rotate", mod.rotate(-4, 1, 2, 3, 4, 5, 6)) - ___'' print("strtonum", mod.strtonum("+123")) print("strtonum", mod.strtonum(" 123 ")) @@ -679,13 +677,26 @@ print("strtonum", mod.strtonum("-1.23")) print("strtonum", mod.strtonum(" 123 abc")) print("strtonum", mod.strtonum("jkl")) - ___'' local a, b, c = mod.requiref() print("requiref", type(a), type(b), type(c), a.boolean, b.boolean, c.boolean, type(requiref1), type(requiref2), type(requiref3)) +___'' +mod.extraspace("abc") +print("getextraspace", mod.extraspace("xyz")) +local c = coroutine.wrap(function() + print("getextraspace", mod.extraspace("uvw")) + print("getextraspace", mod.extraspace("123")) + coroutine.yield() + print("getextraspace", mod.extraspace("asd")) +end) +c() +print("getextraspace", mod.extraspace("456")) +c() +print("getextraspace", mod.extraspace("789")) + ___'' local proxy, backend = {}, {} setmetatable(proxy, { __index = backend, __newindex = backend }) @@ -705,7 +716,7 @@ print("tonumber", mod.tonumber("error")) ___'' print("tointeger", mod.tointeger(12)) -print("tointeger", mod.tointeger(-12)) +print("tointeger", mod.tointeger(12)) print("tointeger", mod.tointeger(12.1)) print("tointeger", mod.tointeger(12.9)) print("tointeger", mod.tointeger(-12.1)) diff --git a/tests/testmod.c b/tests/testmod.c index cd56e76..345a8c9 100644 --- a/tests/testmod.c +++ b/tests/testmod.c @@ -63,6 +63,21 @@ static int test_getseti (lua_State *L) { } +#ifndef LUA_EXTRASPACE +#define LUA_EXTRASPACE (sizeof(void*)) +#endif + +static int test_getextraspace (lua_State *L) { + size_t len = 0; + char const* s = luaL_optlstring(L, 1, NULL, &len); + void* p = lua_getextraspace(L); + lua_pushstring(L, p); + if (s) + memcpy(p, s, len > LUA_EXTRASPACE-1 ? LUA_EXTRASPACE-1 : len+1); + return 1; +} + + /* additional tests for Lua5.1 */ #define NUP 3 @@ -307,6 +322,7 @@ static const luaL_Reg funcs[] = { { "strtonum", test_str2num }, { "requiref", test_requiref }, { "getseti", test_getseti }, + { "extraspace", test_getextraspace }, { "newproxy", test_newproxy }, { "arith", test_arith }, { "compare", test_compare }, -- cgit v1.2.3-55-g6feb