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

Support for Lua 5.4+ & C++17 #111

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
luaversion: [lua-5.1.5,lua-5.2.4,lua-5.3.6,lua-5.4.3]
luaversion: [lua-5.1.5,lua-5.2.4,lua-5.3.6,lua-5.4.3,lua-5.4.7]
fail-fast: false
# The CMake configure and build commands are platform agnostic and should work equally
# well on Windows or Mac. You can convert this to a matrix build if you need
Expand All @@ -24,7 +24,7 @@ jobs:
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Download Lua
run: wget https://www.lua.org/ftp/${{ matrix.luaversion }}.tar.gz && tar zxf ${{ matrix.luaversion }}.tar.gz
- name: Configure CMake
Expand All @@ -40,5 +40,5 @@ jobs:
working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C ${{env.BUILD_TYPE}}
run: ctest --output-on-failure -C ${{env.BUILD_TYPE}}

3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ if(NOT MSVC)#-Wall nonsense on MSVC
add_definitions(-pedantic)
add_definitions(-Wno-variadic-macros)
add_definitions ("-Wno-unused-local-typedefs")
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 13)
add_definitions(-Wno-dangling-reference)
endif()
add_definitions ("-Wno-unknown-warning-option")
#add_definitions("-std=c++11")
endif(NOT MSVC)
Expand Down
7 changes: 3 additions & 4 deletions include/kaguya/detail/lua_function_def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ template <typename Derived> class LuaThreadImpl {
int nresult = 1;
int result = lua_resume(thread, state, argnum, &nresult);
except::checkErrorAndThrow(result, thread);
return detail::FunctionResultProxy::ReturnValue(thread, result, nresult - (lua_gettop(state) + 1),
types::typetag<Result>());
assert(nresult == lua_gettop(thread)); // All results are on top of the thread stack
return detail::FunctionResultProxy::ReturnValue(thread, result, 1, types::typetag<Result>());
}
template <class... Args> FunctionResults operator()(Args &&... args);
#else
Expand Down Expand Up @@ -197,8 +197,7 @@ template <typename Derived> class LuaThreadImpl {
int nresult = 1; \
int result = lua_resume(thread, state, argnum, &nresult); \
except::checkErrorAndThrow(result, thread); \
return detail::FunctionResultProxy::ReturnValue(thread, result, nresult - (lua_gettop(state) + 1), \
types::typetag<Result>()); \
return detail::FunctionResultProxy::ReturnValue(thread, result, 1, types::typetag<Result>()); \
}

KAGUYA_RESUME_DEF(0)
Expand Down
1 change: 1 addition & 0 deletions test/test_01_primitive.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "kaguya/kaguya.hpp"
#include "test_util.hpp"
#include <limits>

KAGUYA_TEST_GROUP_START(test_01_primitive)

Expand Down
35 changes: 34 additions & 1 deletion test/test_04_lua_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ KAGUYA_TEST_FUNCTION_DEF(coroutine)(kaguya::State &state) {
cor2.resume<void>(corfun, 3);
}
{

state["cor2"] = kaguya::NewThread();
kaguya::LuaRef cor2 = state["cor2"];
TEST_CHECK(state("corfun = function(arg)"
Expand All @@ -137,6 +136,40 @@ KAGUYA_TEST_FUNCTION_DEF(coroutine)(kaguya::State &state) {
yieldnum++;
}

TEST_EQUAL(yieldnum, 10);
}
{
// Mix yielding and receiving params
state["cor3"] = kaguya::NewThread();
kaguya::LuaRef cor2 = state["cor3"];
TEST_CHECK(state("corfun = function(arg)"
"for i = 1,arg do "
"j, j1 = coroutine.yield() "
"k = coroutine.yield(j) "
"coroutine.yield(k, j1) "
"end "
"end"));
kaguya::LuaRef corfun = state["corfun"];
kaguya::FunctionResults res0 = cor2(corfun, 10);
TEST_EQUAL(res0.size(), 0u); // 1st yield
int yieldnum = 0;
while (cor2.threadStatus() == LUA_YIELD) {
const int j = yieldnum * 2 + 3;
const int j1 = j + 7;
int res_j = cor2(j, j1);
TEST_EQUAL(res_j, j)
const int k = j + 5;
const kaguya::FunctionResults res_k_j1 = cor2(k);
TEST_EQUAL(res_k_j1.result_size(), 2);
const int res_k = res_k_j1.result_at(0);
const int res_j1 = res_k_j1.result_at(1);
TEST_EQUAL(res_k, k);
TEST_EQUAL(res_j1, j1);
kaguya::FunctionResults res_empty = cor2(); // First in loop or end
TEST_EQUAL(res_empty.size(), 0u);
yieldnum++;
}

TEST_EQUAL(yieldnum, 10);
}
}
Expand Down
9 changes: 8 additions & 1 deletion test/test_06_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,13 @@ KAGUYA_TEST_FUNCTION_DEF(allocation_error_test)(kaguya::State &) {
} catch (const kaguya::LuaMemoryError &) {
continue;
}
#if LUA_VERSION_RELEASE_NUM >= 50404
// In Lua 5.4.4+ we don't get a specific error status for Lua panics
catch (const kaguya::LuaUnknownError & e) {
if (std::string(e.what()).find("memory") != std::string::npos)
continue;
}
#endif
TEST_CHECK(false);
}
}
Expand Down Expand Up @@ -472,7 +479,7 @@ KAGUYA_TEST_FUNCTION_DEF(this_typemismatch_error_test)(kaguya::State &state) {
}
}

#if LUA_VERSION_NUM >= 502
#if LUA_VERSION_NUM >= 502 && LUA_VERSION_NUM < 504
KAGUYA_TEST_FUNCTION_DEF(gc_error_throw_test)(kaguya::State &) {
bool catch_except = false;
try {
Expand Down
2 changes: 1 addition & 1 deletion test/test_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ struct TestClass {
};
}

#if KAGUYA_USE_CPP11
#if KAGUYA_USE_CPP11 && (__cplusplus < 201703L)
inline std::ostream &operator<<(std::ostream &os, std::nullptr_t) {
return os << "nullptr";
}
Expand Down
Loading