diff options
author | Philipp Janda <siffiejoe@gmx.net> | 2017-08-27 10:18:13 +0200 |
---|---|---|
committer | Philipp Janda <siffiejoe@gmx.net> | 2017-08-27 10:18:13 +0200 |
commit | 8b399a1c21ec80b405f1aadeac01d7230922f3b0 (patch) | |
tree | d11498b47e25ebf2b0c9ffddd5f7c25bedc097a1 | |
parent | 7ceb999157d71e29c93c4b2b83ba9c3c46191191 (diff) | |
parent | 67aabb83a1eeea860b1a9a2104c90b80a523268a (diff) | |
download | lua-compat-5.3-8b399a1c21ec80b405f1aadeac01d7230922f3b0.tar.gz lua-compat-5.3-8b399a1c21ec80b405f1aadeac01d7230922f3b0.tar.bz2 lua-compat-5.3-8b399a1c21ec80b405f1aadeac01d7230922f3b0.zip |
Merge branch 'daurnimator-pushstring-return'
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | c-api/compat-5.3.h | 6 | ||||
-rwxr-xr-x | tests/test.lua | 3 | ||||
-rw-r--r-- | tests/testmod.c | 10 |
4 files changed, 20 insertions, 0 deletions
@@ -147,6 +147,7 @@ For Lua 5.1 additionally: | |||
147 | * `lua_arith` (see [here][19]) | 147 | * `lua_arith` (see [here][19]) |
148 | * `lua_compare` | 148 | * `lua_compare` |
149 | * `lua_len`, `lua_rawlen`, and `luaL_len` | 149 | * `lua_len`, `lua_rawlen`, and `luaL_len` |
150 | * `lua_pushstring`, `lua_pushlstring` (return value) | ||
150 | * `lua_copy` | 151 | * `lua_copy` |
151 | * `lua_pushglobaltable` | 152 | * `lua_pushglobaltable` |
152 | * `luaL_testudata` | 153 | * `luaL_testudata` |
diff --git a/c-api/compat-5.3.h b/c-api/compat-5.3.h index 0083eb4..7dd77c6 100644 --- a/c-api/compat-5.3.h +++ b/c-api/compat-5.3.h | |||
@@ -119,6 +119,12 @@ COMPAT53_API void lua_copy (lua_State *L, int from, int to); | |||
119 | #define lua_len COMPAT53_CONCAT(COMPAT53_PREFIX, _len) | 119 | #define lua_len COMPAT53_CONCAT(COMPAT53_PREFIX, _len) |
120 | COMPAT53_API void lua_len (lua_State *L, int i); | 120 | COMPAT53_API void lua_len (lua_State *L, int i); |
121 | 121 | ||
122 | #define lua_pushstring(L, s) \ | ||
123 | (lua_pushstring(L, (s)), lua_tostring(L, -1)) | ||
124 | |||
125 | #define lua_pushlstring(L, s, len) \ | ||
126 | ((((len) == 0) ? lua_pushlstring(L, "", 0) : lua_pushlstring(L, (s), (len))), lua_tostring(L, -1)) | ||
127 | |||
122 | #ifndef luaL_newlibtable | 128 | #ifndef luaL_newlibtable |
123 | # define luaL_newlibtable(L, l) \ | 129 | # define luaL_newlibtable(L, l) \ |
124 | (lua_createtable(L, 0, sizeof(l)/sizeof(*(l))-1)) | 130 | (lua_createtable(L, 0, sizeof(l)/sizeof(*(l))-1)) |
diff --git a/tests/test.lua b/tests/test.lua index be16af9..582f55e 100755 --- a/tests/test.lua +++ b/tests/test.lua | |||
@@ -776,6 +776,9 @@ meta.__name = "XXX" | |||
776 | print(mod.tolstring(ud):gsub(":.*$", ": yyy")) | 776 | print(mod.tolstring(ud):gsub(":.*$", ": yyy")) |
777 | 777 | ||
778 | ___'' | 778 | ___'' |
779 | print(mod.pushstring()) | ||
780 | |||
781 | ___'' | ||
779 | print(mod.buffer()) | 782 | print(mod.buffer()) |
780 | 783 | ||
781 | ___'' | 784 | ___'' |
diff --git a/tests/testmod.c b/tests/testmod.c index 2293064..868136b 100644 --- a/tests/testmod.c +++ b/tests/testmod.c | |||
@@ -246,6 +246,15 @@ static int test_tolstring (lua_State *L) { | |||
246 | return 2; | 246 | return 2; |
247 | } | 247 | } |
248 | 248 | ||
249 | static int test_pushstring (lua_State *L) { | ||
250 | lua_pushstring(L, lua_pushliteral(L, "abc")); | ||
251 | lua_pushstring(L, lua_pushlstring(L, "abc", 2)); | ||
252 | lua_pushstring(L, lua_pushlstring(L, NULL, 0)); | ||
253 | lua_pushstring(L, lua_pushstring(L, "abc")); | ||
254 | lua_pushboolean(L, NULL == lua_pushstring(L, NULL)); | ||
255 | return 10; | ||
256 | } | ||
257 | |||
249 | static int test_buffer (lua_State *L) { | 258 | static int test_buffer (lua_State *L) { |
250 | luaL_Buffer b; | 259 | luaL_Buffer b; |
251 | char *p = luaL_buffinitsize(L, &b, LUAL_BUFFERSIZE+1); | 260 | char *p = luaL_buffinitsize(L, &b, LUAL_BUFFERSIZE+1); |
@@ -285,6 +294,7 @@ static const luaL_Reg funcs[] = { | |||
285 | { "uservalue", test_uservalue }, | 294 | { "uservalue", test_uservalue }, |
286 | { "globals", test_globals }, | 295 | { "globals", test_globals }, |
287 | { "tolstring", test_tolstring }, | 296 | { "tolstring", test_tolstring }, |
297 | { "pushstring", test_pushstring }, | ||
288 | { "buffer", test_buffer }, | 298 | { "buffer", test_buffer }, |
289 | { "exec", test_exec }, | 299 | { "exec", test_exec }, |
290 | { NULL, NULL } | 300 | { NULL, NULL } |