add 'test' library
This commit is contained in:
@@ -37,6 +37,7 @@ extern const luaL_Reg packlib[];
|
||||
extern const luaL_Reg particleslib[]; // gfx.particles
|
||||
extern const luaL_Reg playerlib[];
|
||||
extern const luaL_Reg quatlib[];
|
||||
extern const luaL_Reg testlib[];
|
||||
extern const luaL_Reg text3dlib[]; // gfx.text3d
|
||||
extern const luaL_Reg timelib[];
|
||||
extern const luaL_Reg tomllib[];
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
#include "api_lua.hpp"
|
||||
|
||||
const luaL_Reg testlib[] = {
|
||||
{NULL, NULL}
|
||||
};
|
||||
@@ -2,15 +2,18 @@
|
||||
#include "window/Window.hpp"
|
||||
#include "api_lua.hpp"
|
||||
|
||||
static int l_time_uptime(lua::State* L) {
|
||||
return lua::pushnumber(L, Window::time());
|
||||
using namespace scripting;
|
||||
|
||||
static int l_uptime(lua::State* L) {
|
||||
return lua::pushnumber(L, engine->getUptime());
|
||||
}
|
||||
|
||||
static int l_time_delta(lua::State* L) {
|
||||
return lua::pushnumber(L, scripting::engine->getDelta());
|
||||
static int l_delta(lua::State* L) {
|
||||
return lua::pushnumber(L, engine->getDelta());
|
||||
}
|
||||
|
||||
const luaL_Reg timelib[] = {
|
||||
{"uptime", lua::wrap<l_time_uptime>},
|
||||
{"delta", lua::wrap<l_time_delta>},
|
||||
{NULL, NULL}};
|
||||
{"uptime", lua::wrap<l_uptime>},
|
||||
{"delta", lua::wrap<l_delta>},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "util/stringutil.hpp"
|
||||
#include "libs/api_lua.hpp"
|
||||
#include "lua_custom_types.hpp"
|
||||
#include "engine.hpp"
|
||||
|
||||
static debug::Logger logger("lua-state");
|
||||
static lua::State* main_thread = nullptr;
|
||||
@@ -57,7 +58,10 @@ static void create_libs(State* L, StateType stateType) {
|
||||
openlib(L, "vec3", vec3lib);
|
||||
openlib(L, "vec4", vec4lib);
|
||||
|
||||
if (stateType == StateType::BASE) {
|
||||
if (stateType == StateType::TEST) {
|
||||
openlib(L, "test", testlib);
|
||||
}
|
||||
if (stateType == StateType::BASE || stateType == StateType::TEST) {
|
||||
openlib(L, "gui", guilib);
|
||||
openlib(L, "input", inputlib);
|
||||
openlib(L, "inventory", inventorylib);
|
||||
@@ -110,11 +114,15 @@ void lua::init_state(State* L, StateType stateType) {
|
||||
newusertype<LuaVoxelFragment>(L);
|
||||
}
|
||||
|
||||
void lua::initialize(const EnginePaths& paths) {
|
||||
void lua::initialize(const EnginePaths& paths, const CoreParameters& params) {
|
||||
logger.info() << LUA_VERSION;
|
||||
logger.info() << LUAJIT_VERSION;
|
||||
|
||||
main_thread = create_state(paths, StateType::BASE);
|
||||
main_thread = create_state(
|
||||
paths, params.headless ? StateType::TEST : StateType::BASE
|
||||
);
|
||||
lua::pushstring(main_thread, params.testFile.stem().u8string());
|
||||
lua::setglobal(main_thread, "__VC_TEST_NAME");
|
||||
}
|
||||
|
||||
void lua::finalize() {
|
||||
|
||||
@@ -8,14 +8,16 @@
|
||||
#include "lua_util.hpp"
|
||||
|
||||
class EnginePaths;
|
||||
struct CoreParameters;
|
||||
|
||||
namespace lua {
|
||||
enum class StateType {
|
||||
BASE,
|
||||
TEST,
|
||||
GENERATOR,
|
||||
};
|
||||
|
||||
void initialize(const EnginePaths& paths);
|
||||
void initialize(const EnginePaths& paths, const CoreParameters& params);
|
||||
void finalize();
|
||||
|
||||
bool emit_event(
|
||||
|
||||
Reference in New Issue
Block a user