Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt tests to evaluate the integration with LuaMemory module. #1

Draft
wants to merge 3 commits into
base: v5.3
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -143,7 +143,7 @@ do
-- each time a table is collected, remark it for finalization
-- on next cycle
mt.__gc = function (o)
stderr:write'.' -- mark progress
--stderr:write'.' -- mark progress
local n = setmetatable(o, mt) -- remark it
end
local n = setmetatable({}, mt) -- create object
@@ -155,6 +155,10 @@ f()

dofile('db.lua')
assert(dofile('calls.lua') == deep and deep)
dofile('errors.lua')

dofile("luamem_wrapapi.lua")

olddofile('strings.lua')
olddofile('literals.lua')
dofile('tpack.lua')
@@ -178,7 +182,6 @@ dofile('vararg.lua')
dofile('closure.lua')
dofile('coroutine.lua')
dofile('goto.lua', true)
dofile('errors.lua')
dofile('math.lua')
dofile('sort.lua', true)
dofile('bitwise.lua')
@@ -308,7 +308,7 @@ assert(count(3) == 2)
assert(count('alo') == 1)
assert(count('32') == 2)
assert(count({}) == 1)
assert(count(print) == 2)
assert(count(assert) == 2)
assert(count(function () end) == 1)
assert(count(nil) == 1)
assert(count(io.stdin) == 1)
@@ -240,8 +240,8 @@ assert(foo3() == 10 + 3)
assert(not pcall(debug.upvaluejoin, foo1, 3, foo2, 1))
assert(not pcall(debug.upvaluejoin, foo1, 1, foo2, 3))
assert(not pcall(debug.upvaluejoin, foo1, 0, foo2, 1))
assert(not pcall(debug.upvaluejoin, print, 1, foo2, 1))
assert(not pcall(debug.upvaluejoin, error, 1, foo2, 1))
assert(not pcall(debug.upvaluejoin, {}, 1, foo2, 1))
assert(not pcall(debug.upvaluejoin, foo1, 1, print, 1))
assert(not pcall(debug.upvaluejoin, foo1, 1, error, 1))

print'OK'
@@ -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;
}

@@ -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);
}


@@ -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;
}


@@ -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);
}


@@ -0,0 +1,26 @@
# 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

lib1.so: lib1.c
$(CC) $(CFLAGS) -o lib1.so lib1.c

lib11.so: lib11.c
$(CC) $(CFLAGS) -o lib11.so lib11.c

lib2.so: lib2.c
$(CC) $(CFLAGS) -o lib2.so lib2.c

lib21.so: lib21.c
$(CC) $(CFLAGS) -o lib21.so lib21.c

lib2-v2.so: lib2.so
mv lib2.so ./lib2-v2.so