aboutsummaryrefslogtreecommitdiffstats
path: root/tests/testmod.c
diff options
context:
space:
mode:
authorLibravatarLibravatar daurnimator <quae@daurnimator.com> 2018-05-30 17:48:40 +1000
committerLibravatarLibravatar daurnimator <quae@daurnimator.com> 2018-05-30 17:48:40 +1000
commit18b7d200cbaadf7aee592f739e2e0cb4be4ce298 (patch)
treeb231730217df8f635734467d2f186a625d3d0900 /tests/testmod.c
parent7333333568b13db56136e2354c55556adc7714ed (diff)
downloadluaossl-18b7d200cbaadf7aee592f739e2e0cb4be4ce298.tar.gz
luaossl-18b7d200cbaadf7aee592f739e2e0cb4be4ce298.tar.bz2
luaossl-18b7d200cbaadf7aee592f739e2e0cb4be4ce298.zip
Squashed 'vendor/compat53/' changes from 6f3deea..bc91f40
bc91f40 Merge pull request #38 from ThePhD/warnings/vcxx 3615e44 fix VC warnings for integer down-conversions to char db8446d Merge pull request #37 from keplerproject/strerror 447deca Add braces and suppress warning. b782901 Do less stuff when sz is 0 in compat53_strerror(). 9895acb Transparently handle GNU/XSI strerror_r. 9cb6834 Add Travis-CI integration ee2d198 Fix links in the README.md. c381aa3 Merge branch 'ThePhD-feature/luaL_loadfilebufferx' 09b201c Add tests for `luaL_load{buffer,file}x`. 3b52d81 Add Lua 5.3 version of `lua_load`. 8425f99 Merge branch 'feature/luaL_loadfilebufferx' of https://github.com/ThePhD/lua-compat-5.3 into ThePhD-feature/luaL_loadfilebufferx 9435c6c Merge branch 'daurnimator-luaL_Stream' bf96f3d Include lualib.h, remove #define LUA_FILEHANDLE. f76fb00 Merge branch 'luaL_Stream' of https://github.com/daurnimator/lua-compat-5.3 into daurnimator-luaL_Stream 7fc7aba Merge branch 'ThePhD-fix/lua_Number_casts' ee862eb Merge branch 'fix/lua_Number_casts' of https://github.com/ThePhD/lua-compat-5.3 into ThePhD-fix/lua_Number_casts f3b1160 Merge branch 'ThePhD-feature/LUA_ERRGCMM' 73a7b6b fix usage of tabs 0c9d432 fix `lua_Integer` casts that error on Visual C++ and other pedantic conversion-warning compilers for 64-bit builds 7320d58 define LUA_ERRGCMM code for return values 6065d10 update readme 8ee5245 implement luaL_loadbufferx and luaL_loadfilex 0821294 Merge pull request #26 from daurnimator/lua_resume c0a59dd Add (partial) luaL_Stream definition c0db566 Add LUA_FILEHANDLE define 690239b Add lua_resume 1037026 Merge pull request #24 from daurnimator/implicit-fallthrough a3f456a Use FALLTHROUGH annotation to fix -Wimplicit-fallthrough warning git-subtree-dir: vendor/compat53 git-subtree-split: bc91f40919196e6af6371c26f851f8f94da0b15c
Diffstat (limited to 'tests/testmod.c')
-rw-r--r--tests/testmod.c39
1 files changed, 36 insertions, 3 deletions
diff --git a/tests/testmod.c b/tests/testmod.c
index 868136b..a0d2e2a 100644
--- a/tests/testmod.c
+++ b/tests/testmod.c
@@ -1,7 +1,5 @@
#include <stdio.h>
#include <stdlib.h>
-#include <lua.h>
-#include <lauxlib.h>
#include "compat-5.3.h"
@@ -12,7 +10,7 @@ static int test_isinteger (lua_State *L) {
static int test_rotate (lua_State *L) {
- int r = luaL_checkint(L, 1);
+ int r = (int)luaL_checkinteger(L, 1);
int n = lua_gettop(L)-1;
luaL_argcheck(L, (r < 0 ? -r : r) <= n, 1, "not enough arguments");
lua_rotate(L, 2, r);
@@ -274,6 +272,33 @@ static int test_exec (lua_State *L) {
return luaL_execresult(L, system(cmd));
}
+static int test_loadstring (lua_State *L) {
+ size_t len = 0;
+ char const* s = luaL_checklstring(L, 1, &len);
+ char const* mode = luaL_optstring(L, 2, "bt");
+ lua_pushinteger(L, luaL_loadbufferx(L, s, len, s, mode));
+ return 2;
+}
+
+static int test_loadfile (lua_State *L) {
+ char filename[L_tmpnam+1] = { 0 };
+ size_t len = 0;
+ char const* s = luaL_checklstring(L, 1, &len);
+ char const* mode = luaL_optstring(L, 2, "bt");
+ if (tmpnam(filename)) {
+ FILE* f = fopen(filename, "wb");
+ if (f) {
+ fwrite(s, 1, len, f);
+ fclose(f);
+ lua_pushinteger(L, luaL_loadfilex(L, filename, mode));
+ remove(filename);
+ return 2;
+ } else
+ remove(filename);
+ }
+ return 0;
+}
+
static const luaL_Reg funcs[] = {
{ "isinteger", test_isinteger },
@@ -297,6 +322,8 @@ static const luaL_Reg funcs[] = {
{ "pushstring", test_pushstring },
{ "buffer", test_buffer },
{ "exec", test_exec },
+ { "loadstring", test_loadstring },
+ { "loadfile", test_loadfile },
{ NULL, NULL }
};
@@ -307,6 +334,9 @@ static const luaL_Reg more_funcs[] = {
};
+#ifdef __cplusplus
+extern "C" {
+#endif
int luaopen_testmod (lua_State *L) {
int i = 1;
luaL_newlib(L, funcs);
@@ -315,4 +345,7 @@ int luaopen_testmod (lua_State *L) {
luaL_setfuncs(L, more_funcs, NUP);
return 1;
}
+#ifdef __cplusplus
+}
+#endif