MCPcopy Create free account
hub / github.com/PolygonTek/BlueshiftEngine / TestModule

Function TestModule

Source/TestBase/TestLua.cpp:277–309  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

275}
276
277static void TestModule(LuaCpp::State &lua) {
278 lua.RegisterSearcher([&lua](const std::string &name) {
279 printf(name.c_str());
280 return true;
281 });
282
283 lua.RegisterModule("blueshift.math", [](LuaCpp::Module &module) {
284 module["Vec3"].SetClass<BE1::Vec3>();
285 module["Vec3"].AddClassCtor<BE1::Vec3, float, float, float>("__call");
286 module["Vec3"].AddClassMembers<BE1::Vec3>(
287 "x", &BE1::Vec3::x,
288 "y", &BE1::Vec3::y,
289 "z", &BE1::Vec3::z
290 );
291
292 module["sub"].SetFunc([](int a, int b) {
293 return a - b;
294 });
295 });
296
297 lua.RunBuffer("TestModule", R"(
298 --print(package.path) -- default path
299 --print(package.cpath) -- default cpath
300 print(_ENV, _G) -- _ENV is not defined by Lua 5.1
301 local haha = require "haha"
302 local math = require "blueshift.math"
303 local math2 = require "blueshift.math"
304 local Vec3 = math.Vec3
305 --print(type(Vec3))
306 local v = Vec3(1, 2, 3)
307 print(v:x(), v:y(), v:z())
308 )", 0, "sandbox");
309}
310
311static void TestCompile(LuaCpp::State &lua) {
312 std::string byteCode;

Callers 1

TestLuaFunction · 0.85

Calls 5

RegisterSearcherMethod · 0.80
RegisterModuleMethod · 0.80
SetFuncMethod · 0.80
RunBufferMethod · 0.80
c_strMethod · 0.45

Tested by

no test coverage detected