aboutsummaryrefslogtreecommitdiff
path: root/tests/testmod.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/testmod.c')
-rw-r--r--tests/testmod.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/testmod.c b/tests/testmod.c
index 868136b..1034d20 100644
--- a/tests/testmod.c
+++ b/tests/testmod.c
@@ -274,6 +274,33 @@ static int test_exec (lua_State *L) {
274 return luaL_execresult(L, system(cmd)); 274 return luaL_execresult(L, system(cmd));
275} 275}
276 276
277static int test_loadstring (lua_State *L) {
278 size_t len = 0;
279 char const* s = luaL_checklstring(L, 1, &len);
280 char const* mode = luaL_optstring(L, 2, "bt");
281 lua_pushinteger(L, luaL_loadbufferx(L, s, len, s, mode));
282 return 2;
283}
284
285static int test_loadfile (lua_State *L) {
286 char filename[L_tmpnam+1] = { 0 };
287 size_t len = 0;
288 char const* s = luaL_checklstring(L, 1, &len);
289 char const* mode = luaL_optstring(L, 2, "bt");
290 if (tmpnam(filename)) {
291 FILE* f = fopen(filename, "wb");
292 if (f) {
293 fwrite(s, 1, len, f);
294 fclose(f);
295 lua_pushinteger(L, luaL_loadfilex(L, filename, mode));
296 remove(filename);
297 return 2;
298 } else
299 remove(filename);
300 }
301 return 0;
302}
303
277 304
278static const luaL_Reg funcs[] = { 305static const luaL_Reg funcs[] = {
279 { "isinteger", test_isinteger }, 306 { "isinteger", test_isinteger },
@@ -297,6 +324,8 @@ static const luaL_Reg funcs[] = {
297 { "pushstring", test_pushstring }, 324 { "pushstring", test_pushstring },
298 { "buffer", test_buffer }, 325 { "buffer", test_buffer },
299 { "exec", test_exec }, 326 { "exec", test_exec },
327 { "loadstring", test_loadstring },
328 { "loadfile", test_loadfile },
300 { NULL, NULL } 329 { NULL, NULL }
301}; 330};
302 331