-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8f51c4b
commit e25abe4
Showing
2 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
Submodule lua
updated
24 files
+21 −7 | lauxlib.c | |
+6 −3 | lcode.c | |
+105 −89 | ldebug.c | |
+4 −0 | ldo.c | |
+1 −1 | lgc.c | |
+20 −7 | liolib.c | |
+1 −1 | lmathlib.c | |
+2 −0 | loslib.c | |
+1 −1 | lstring.c | |
+25 −11 | ltable.c | |
+8 −2 | ltests.c | |
+10 −10 | lua.c | |
+12 −22 | lua.h | |
+1 −1 | luaconf.h | |
+1 −1 | lundump.h | |
+2 −2 | lvm.c | |
+1 −1 | manual/2html | |
+18 −11 | manual/manual.of | |
+8 −0 | testes/closure.lua | |
+5 −3 | testes/coroutine.lua | |
+9 −0 | testes/db.lua | |
+17 −1 | testes/errors.lua | |
+5 −0 | testes/main.lua | |
+2 −1 | testes/pm.lua |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include <gtest/gtest.h> | ||
#include <lua.h> | ||
#include <lualib.h> | ||
#include <lauxlib.h> | ||
#include <memory> | ||
|
||
|
||
static std::weak_ptr<int> ptr; | ||
|
||
static int func(lua_State *L) { | ||
auto mem = std::make_shared<int>(42); | ||
ptr = mem; | ||
asm volatile("": : :"memory"); | ||
luaL_error(L, "error"); | ||
return 0; | ||
} | ||
|
||
TEST(LuaTest, CppStackUnwrap) { | ||
// Lua needs to be configured to use C++ exceptions instead of longjmp for this to succeed | ||
auto initial = std::make_shared<int>(0); | ||
ptr = initial; | ||
|
||
lua_State* L = luaL_newstate(); | ||
ASSERT_TRUE(L); | ||
lua_pushcfunction(L, func); | ||
lua_setglobal(L, "func"); | ||
luaL_loadstring(L, "func()"); | ||
auto res = lua_pcall(L, 0, 0, 0); | ||
EXPECT_NE(res, 0) << "Lua func did not throw"; | ||
lua_close(L); | ||
|
||
if (auto p = ptr.lock()) { | ||
ASSERT_EQ(*p, 42) << "Lua func was never run"; | ||
} | ||
EXPECT_TRUE(ptr.expired()) << "Lua func did not properly unwrap the stack"; | ||
} | ||
|
||
TEST(LuaTest, AssignToItorator) { | ||
// This is a breaking change for many packs in the preview of Lua 5.5 | ||
// not sure what to do once 5.4 reaches EOL | ||
auto script = R""""( | ||
local table = {a = "x", b = "y", c = "z"} | ||
local n = 0 | ||
for k, v in pairs(table) do | ||
k = k .. ":" -- this assignment fails in Lua 5.5 preview | ||
n = n + 1 | ||
end | ||
assert(n == 3, "Iteration did not succeed") | ||
)""""; | ||
|
||
lua_State* L = luaL_newstate(); | ||
ASSERT_TRUE(L); | ||
luaL_requiref(L, LUA_GNAME, luaopen_base, 1); | ||
lua_pop(L, 1); | ||
luaL_loadstring(L, script); | ||
auto res = lua_pcall(L, 0, 0, 0); | ||
EXPECT_EQ(res, 0) << lua_tostring(L, -1); | ||
lua_close(L); | ||
} |