Przeglądaj źródła

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.
Roberto Ierusalimschy 6 lat temu
rodzic
commit
01bded3d8c
3 zmienionych plików z 28 dodań i 3 usunięć
  1. 1 1
      testes/attrib.lua
  2. 25 0
      testes/libs/lib22.c
  3. 2 2
      testes/libs/makefile

+ 1 - 1
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"

+ 25 - 0
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;
+}
+
+

+ 2 - 2
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