aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPhilipp Janda <siffiejoe@gmx.net>2015-01-21 14:34:11 +0100
committerPhilipp Janda <siffiejoe@gmx.net>2015-01-21 14:34:11 +0100
commitc57750c925553f627701f2c4897ee6bd6488c7c1 (patch)
tree465e24fcc87ab8a49baf3e4dec380871275cd486 /tests
parent866cb79f65c844b3fcfa99d2caa4bf19930dbc6d (diff)
downloadlua-compat-5.3-c57750c925553f627701f2c4897ee6bd6488c7c1.tar.gz
lua-compat-5.3-c57750c925553f627701f2c4897ee6bd6488c7c1.tar.bz2
lua-compat-5.3-c57750c925553f627701f2c4897ee6bd6488c7c1.zip
backport Lua 5.2/5.3 buffer API for Lua 5.1
Diffstat (limited to 'tests')
-rwxr-xr-xtests/test.lua3
-rw-r--r--tests/testmod.c15
2 files changed, 18 insertions, 0 deletions
diff --git a/tests/test.lua b/tests/test.lua
index 98259fe..83e174e 100755
--- a/tests/test.lua
+++ b/tests/test.lua
@@ -679,5 +679,8 @@ local t = setmetatable({}, {
679 __tostring = function(v) return nil end 679 __tostring = function(v) return nil end
680}) 680})
681print(pcall(mod.tolstring, t)) 681print(pcall(mod.tolstring, t))
682
683___''
684print(mod.buffer())
682___'' 685___''
683 686
diff --git a/tests/testmod.c b/tests/testmod.c
index 2c6242b..f89b10a 100644
--- a/tests/testmod.c
+++ b/tests/testmod.c
@@ -242,6 +242,20 @@ static int test_tolstring (lua_State *L) {
242 return 2; 242 return 2;
243} 243}
244 244
245static int test_buffer (lua_State *L) {
246 luaL_Buffer b;
247 char *p = luaL_buffinitsize(L, &b, LUAL_BUFFERSIZE+1);
248 p[0] = 'a';
249 p[1] = 'b';
250 luaL_addsize(&b, 2);
251 luaL_addstring(&b, "c");
252 lua_pushliteral(L, "d");
253 luaL_addvalue(&b);
254 luaL_addchar(&b, 'e');
255 luaL_pushresult(&b);
256 return 1;
257}
258
245 259
246static const luaL_Reg funcs[] = { 260static const luaL_Reg funcs[] = {
247 { "isinteger", test_isinteger }, 261 { "isinteger", test_isinteger },
@@ -262,6 +276,7 @@ static const luaL_Reg funcs[] = {
262 { "uservalue", test_uservalue }, 276 { "uservalue", test_uservalue },
263 { "globals", test_globals }, 277 { "globals", test_globals },
264 { "tolstring", test_tolstring }, 278 { "tolstring", test_tolstring },
279 { "buffer", test_buffer },
265 { NULL, NULL } 280 { NULL, NULL }
266}; 281};
267 282