aboutsummaryrefslogtreecommitdiff
path: root/unit_tests/embedded_tests.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'unit_tests/embedded_tests.cpp')
-rw-r--r--unit_tests/embedded_tests.cpp22
1 files changed, 13 insertions, 9 deletions
diff --git a/unit_tests/embedded_tests.cpp b/unit_tests/embedded_tests.cpp
index 9a262d5..388548d 100644
--- a/unit_tests/embedded_tests.cpp
+++ b/unit_tests/embedded_tests.cpp
@@ -2,6 +2,7 @@
2#include "shared.h" 2#include "shared.h"
3#include "lanes/src/lanes.hpp" 3#include "lanes/src/lanes.hpp"
4 4
5#if defined __has_include && __has_include(<windows.h>)
5#include <windows.h> 6#include <windows.h>
6 7
7// ################################################################################################# 8// #################################################################################################
@@ -138,13 +139,13 @@ namespace
138 139
139// ################################################################################################# 140// #################################################################################################
140 141
141TEST_CASE("lanes.embedding.with default allocator") 142TEST_CASE("lanes.embedding.with_default_allocator")
142{ 143{
143 local::EmbeddedLuaState S; 144 local::EmbeddedLuaState S;
144 145
145 // --------------------------------------------------------------------------------------------- 146 // ---------------------------------------------------------------------------------------------
146 147
147 SECTION("single state") 148 SECTION("single_state")
148 { 149 {
149 // this sends data in a linda. current contents: 150 // this sends data in a linda. current contents:
150 // key: short string 151 // key: short string
@@ -157,7 +158,7 @@ TEST_CASE("lanes.embedding.with default allocator")
157 // function with an upvalue 158 // function with an upvalue
158 std::string_view const _script{ 159 std::string_view const _script{
159 " local lanes = require 'lanes'.configure{with_timers = false}" 160 " local lanes = require 'lanes'.configure{with_timers = false}"
160 " local l = lanes.linda'gleh'" 161 " local l = lanes.linda{name = 'gleh'}"
161 " local upvalue = 'oeauaoeuoeuaoeuaoeujaoefubycfjbycfybcfjybcfjybcfjbcf'" 162 " local upvalue = 'oeauaoeuoeuaoeuaoeujaoefubycfjbycfybcfjybcfjybcfjbcf'"
162 " local upvalued = function()" 163 " local upvalued = function()"
163 " return upvalue" 164 " return upvalue"
@@ -171,7 +172,7 @@ TEST_CASE("lanes.embedding.with default allocator")
171 172
172 // --------------------------------------------------------------------------------------------- 173 // ---------------------------------------------------------------------------------------------
173 174
174 SECTION("manual registration") 175 SECTION("manual_registration")
175 { 176 {
176 S.requireSuccess("require 'lanes'.configure{with_timers = false}"); 177 S.requireSuccess("require 'lanes'.configure{with_timers = false}");
177 178
@@ -183,7 +184,7 @@ TEST_CASE("lanes.embedding.with default allocator")
183 // try to send io.open into a linda, which fails if io base library is not loaded 184 // try to send io.open into a linda, which fails if io base library is not loaded
184 std::string_view const _script{ 185 std::string_view const _script{
185 " local lanes = require 'lanes'" 186 " local lanes = require 'lanes'"
186 " local l = lanes.linda'gleh'" 187 " local l = lanes.linda{name = 'gleh'}"
187 " l:set('yo', io.open)" 188 " l:set('yo', io.open)"
188 " return 'SUCCESS'" 189 " return 'SUCCESS'"
189 }; 190 };
@@ -191,7 +192,7 @@ TEST_CASE("lanes.embedding.with default allocator")
191 192
192 // try again after manual registration 193 // try again after manual registration
193 lua_pushcfunction(S, S.get_lanes_register()); // S: lanes_register 194 lua_pushcfunction(S, S.get_lanes_register()); // S: lanes_register
194 luaG_pushstring(S, LUA_IOLIBNAME); // S: lanes_register "io" 195 luaW_pushstring(S, LUA_IOLIBNAME); // S: lanes_register "io"
195 luaL_requiref(S, LUA_IOLIBNAME, luaopen_io, 1); // S: lanes_register "io" io 196 luaL_requiref(S, LUA_IOLIBNAME, luaopen_io, 1); // S: lanes_register "io" io
196 lua_call(S, 2, 0); // S: 197 lua_call(S, 2, 0); // S:
197 S.stackCheck(0); 198 S.stackCheck(0);
@@ -202,7 +203,8 @@ TEST_CASE("lanes.embedding.with default allocator")
202// ################################################################################################# 203// #################################################################################################
203 204
204// this is not really a test yet, just something sitting here until it is converted properly 205// this is not really a test yet, just something sitting here until it is converted properly
205TEST_CASE("lanes.embedding.with custom allocator") 206// currently it crashes with moonjit (but maybe I just need a more recent moonjit version)
207TEST_CASE("lanes.embedding.with_custom_allocator")
206{ 208{
207 static constexpr auto logPrint = +[](lua_State* L) { 209 static constexpr auto logPrint = +[](lua_State* L) {
208 lua_getglobal(L, "ID"); // ID 210 lua_getglobal(L, "ID"); // ID
@@ -218,7 +220,7 @@ TEST_CASE("lanes.embedding.with custom allocator")
218 220
219 static constexpr auto launch_lane = +[](lua_CFunction on_state_create_, int id_, int n_) { 221 static constexpr auto launch_lane = +[](lua_CFunction on_state_create_, int id_, int n_) {
220 char script[500]; 222 char script[500];
221 lua_State* L = lua_newstate(local::allocf, nullptr); 223 lua_State* L = luaW_newstate(local::allocf, nullptr, luaL_makeseed(nullptr));
222 // _G.ID = id_ 224 // _G.ID = id_
223 luaL_openlibs(L); 225 luaL_openlibs(L);
224 luaL_dostring(L, "lanes = require 'lanes'"); 226 luaL_dostring(L, "lanes = require 'lanes'");
@@ -264,4 +266,6 @@ TEST_CASE("lanes.embedding.with custom allocator")
264 lua_close(L3); 266 lua_close(L3);
265 lua_close(L2); 267 lua_close(L2);
266 lua_close(L1); 268 lua_close(L1);
267} \ No newline at end of file 269}
270
271#endif // windows.h