diff options
| author | 2025-12-07 12:44:18 +0100 | |
|---|---|---|
| committer | 2025-12-07 12:44:18 +0100 | |
| commit | 6a335e2b7d47afdb5e37034a095aaa26a34d7ee1 (patch) | |
| tree | b7aae9d679df13ce04f695670e80a8e7a73361c9 /test/external/lua-5.4.0-tests/libs | |
| parent | bfc6b66078ab3ec543b8355ad22df1c423bf9a8c (diff) | |
Add lua 5.4.0 test suite
Diffstat (limited to 'test/external/lua-5.4.0-tests/libs')
| -rw-r--r-- | test/external/lua-5.4.0-tests/libs/lib1.c | 44 | ||||
| -rw-r--r-- | test/external/lua-5.4.0-tests/libs/lib11.c | 10 | ||||
| -rw-r--r-- | test/external/lua-5.4.0-tests/libs/lib2.c | 23 | ||||
| -rw-r--r-- | test/external/lua-5.4.0-tests/libs/lib21.c | 10 | ||||
| -rw-r--r-- | test/external/lua-5.4.0-tests/libs/lib22.c | 25 | ||||
| -rw-r--r-- | test/external/lua-5.4.0-tests/libs/makefile | 27 |
6 files changed, 139 insertions, 0 deletions
diff --git a/test/external/lua-5.4.0-tests/libs/lib1.c b/test/external/lua-5.4.0-tests/libs/lib1.c new file mode 100644 index 0000000..56b6ef4 --- /dev/null +++ b/test/external/lua-5.4.0-tests/libs/lib1.c @@ -0,0 +1,44 @@ +#include "lua.h" +#include "lauxlib.h" + +static int id (lua_State *L) { + return lua_gettop(L); +} + + +static const struct luaL_Reg funcs[] = { + {"id", id}, + {NULL, NULL} +}; + + +/* function used by lib11.c */ +LUAMOD_API int lib1_export (lua_State *L) { + lua_pushstring(L, "exported"); + return 1; +} + + +LUAMOD_API int onefunction (lua_State *L) { + luaL_checkversion(L); + lua_settop(L, 2); + lua_pushvalue(L, 1); + return 2; +} + + +LUAMOD_API int anotherfunc (lua_State *L) { + luaL_checkversion(L); + lua_pushfstring(L, "%d%%%d\n", (int)lua_tointeger(L, 1), + (int)lua_tointeger(L, 2)); + return 1; +} + + +LUAMOD_API int luaopen_lib1_sub (lua_State *L) { + lua_setglobal(L, "y"); /* 2nd arg: extra value (file name) */ + lua_setglobal(L, "x"); /* 1st arg: module name */ + luaL_newlib(L, funcs); + return 1; +} + diff --git a/test/external/lua-5.4.0-tests/libs/lib11.c b/test/external/lua-5.4.0-tests/libs/lib11.c new file mode 100644 index 0000000..377d0c4 --- /dev/null +++ b/test/external/lua-5.4.0-tests/libs/lib11.c @@ -0,0 +1,10 @@ +#include "lua.h" + +/* function from lib1.c */ +int lib1_export (lua_State *L); + +LUAMOD_API int luaopen_lib11 (lua_State *L) { + return lib1_export(L); +} + + diff --git a/test/external/lua-5.4.0-tests/libs/lib2.c b/test/external/lua-5.4.0-tests/libs/lib2.c new file mode 100644 index 0000000..bc9651e --- /dev/null +++ b/test/external/lua-5.4.0-tests/libs/lib2.c @@ -0,0 +1,23 @@ +#include "lua.h" +#include "lauxlib.h" + +static int id (lua_State *L) { + return lua_gettop(L); +} + + +static const struct luaL_Reg funcs[] = { + {"id", id}, + {NULL, NULL} +}; + + +LUAMOD_API int luaopen_lib2 (lua_State *L) { + lua_settop(L, 2); + lua_setglobal(L, "y"); /* y gets 2nd parameter */ + lua_setglobal(L, "x"); /* x gets 1st parameter */ + luaL_newlib(L, funcs); + return 1; +} + + diff --git a/test/external/lua-5.4.0-tests/libs/lib21.c b/test/external/lua-5.4.0-tests/libs/lib21.c new file mode 100644 index 0000000..a39b683 --- /dev/null +++ b/test/external/lua-5.4.0-tests/libs/lib21.c @@ -0,0 +1,10 @@ +#include "lua.h" + + +int luaopen_lib2 (lua_State *L); + +LUAMOD_API int luaopen_lib21 (lua_State *L) { + return luaopen_lib2(L); +} + + diff --git a/test/external/lua-5.4.0-tests/libs/lib22.c b/test/external/lua-5.4.0-tests/libs/lib22.c new file mode 100644 index 0000000..8e65650 --- /dev/null +++ b/test/external/lua-5.4.0-tests/libs/lib22.c @@ -0,0 +1,25 @@ +#include "lua.h" +#include "lauxlib.h" + +static int id (lua_State *L) { + lua_pushboolean(L, 1); + lua_insert(L, 1); + return lua_gettop(L); +} + + +static const struct luaL_Reg funcs[] = { + {"id", id}, + {NULL, NULL} +}; + + +LUAMOD_API int luaopen_lib2 (lua_State *L) { + lua_settop(L, 2); + lua_setglobal(L, "y"); /* y gets 2nd parameter */ + lua_setglobal(L, "x"); /* x gets 1st parameter */ + luaL_newlib(L, funcs); + return 1; +} + + diff --git a/test/external/lua-5.4.0-tests/libs/makefile b/test/external/lua-5.4.0-tests/libs/makefile new file mode 100644 index 0000000..a133092 --- /dev/null +++ b/test/external/lua-5.4.0-tests/libs/makefile @@ -0,0 +1,27 @@ +# change this variable to point to the directory with Lua headers +# of the version being tested +LUA_DIR = ../../ + +CC = gcc + +# compilation should generate Dynamic-Link Libraries +CFLAGS = -Wall -std=gnu99 -O2 -I$(LUA_DIR) -fPIC -shared + +# libraries used by the tests +all: lib1.so lib11.so lib2.so lib21.so lib2-v2.so + touch all + +lib1.so: lib1.c $(LUA_DIR)/luaconf.h + $(CC) $(CFLAGS) -o lib1.so lib1.c + +lib11.so: lib11.c $(LUA_DIR)/luaconf.h + $(CC) $(CFLAGS) -o lib11.so lib11.c + +lib2.so: lib2.c $(LUA_DIR)/luaconf.h + $(CC) $(CFLAGS) -o lib2.so lib2.c + +lib21.so: lib21.c $(LUA_DIR)/luaconf.h + $(CC) $(CFLAGS) -o lib21.so lib21.c + +lib2-v2.so: lib21.c $(LUA_DIR)/luaconf.h + $(CC) $(CFLAGS) -o lib2-v2.so lib22.c |