From 01bded3d8cd88a2d7f472b45f706565f1a9ef3b1 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Fri, 3 May 2019 10:36:19 -0300 Subject: File 'lib2-v2.so' generated from its own source Instead of being a copy of 'lib2.so', 'lib2-v2.so' has its own source file ('lib22.c'), so that the test can distinguish both libraries. --- testes/attrib.lua | 2 +- testes/libs/lib22.c | 25 +++++++++++++++++++++++++ testes/libs/makefile | 4 ++-- 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 testes/libs/lib22.c diff --git a/testes/attrib.lua b/testes/attrib.lua index 4adb42e0..b1a4a199 100644 --- a/testes/attrib.lua +++ b/testes/attrib.lua @@ -275,7 +275,7 @@ else -- check correct access to global environment and correct -- parameters assert(_ENV.x == "lib2-v2" and _ENV.y == DC"lib2-v2") - assert(lib2.id("x") == "x") + assert(lib2.id("x") == true) -- a different "id" implementation -- test C submodules local fs, ext = require"lib1.sub" diff --git a/testes/libs/lib22.c b/testes/libs/lib22.c new file mode 100644 index 00000000..8e656502 --- /dev/null +++ b/testes/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/testes/libs/makefile b/testes/libs/makefile index acff4848..698f8984 100644 --- a/testes/libs/makefile +++ b/testes/libs/makefile @@ -23,5 +23,5 @@ lib2.so: lib2.c $(LUA_DIR)/luaconf.h $(LUA_DIR)/ltests.h lib21.so: lib21.c $(LUA_DIR)/luaconf.h $(LUA_DIR)/ltests.h $(CC) $(CFLAGS) -o lib21.so lib21.c -lib2-v2.so: lib2.so - cp lib2.so ./lib2-v2.so +lib2-v2.so: lib21.c $(LUA_DIR)/luaconf.h $(LUA_DIR)/ltests.h + $(CC) $(CFLAGS) -o lib2-v2.so lib22.c -- cgit v1.2.3-55-g6feb