Skip to content

Commit 867851d

Browse files
test: added do_file test
1 parent 35d7c1a commit 867851d

3 files changed

Lines changed: 32 additions & 1 deletion

File tree

tests/assets/script.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Siple script to print 'Hello Lua'
2+
require('io')
3+
4+
io.write('Hello Lua!')

tests/meson.build

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
tests_src = {
2-
'simple': ['src/simple.c']
2+
'simple': ['src/simple.c'],
3+
'do_file': ['src/do_file.c']
34
}
45

56
tests_inc = include_directories(['include'])

tests/src/do_file.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
4+
#include "lua.h"
5+
#include "lualib.h"
6+
#include "lauxlib.h"
7+
8+
int main(int argc, char **argv)
9+
{
10+
int result;
11+
lua_State *L = luaL_newstate();
12+
luaL_openlibs(L);
13+
14+
result = luaL_dofile(L, "../tests/assets/script.lua");
15+
16+
if (result != LUA_OK)
17+
{
18+
fprintf(stderr, "Error: %s\n", lua_tostring(L, -1));
19+
lua_pop(L, 1);
20+
return 1;
21+
}
22+
23+
lua_close(L);
24+
25+
return 0;
26+
}

0 commit comments

Comments
 (0)