add: lua func

This commit is contained in:
Cogi Asd
2024-07-07 23:53:27 +03:00
parent 2f2d6a69e8
commit 7a1c035f01
7 changed files with 114 additions and 4 deletions
+31
View File
@@ -11,6 +11,7 @@
#include "../../../window/Events.hpp"
#include "../../../window/Window.hpp"
#include "../../../world/WorldGenerators.hpp"
#include "../../../constants.hpp"
#include <vector>
#include <memory>
@@ -158,6 +159,35 @@ static int l_get_generators(lua::State* L) {
return 1;
}
static int l_get_constants(lua::State* L) {
lua::createtable(L, 0, 20);
const std::pair<const char*, int> numberConstants[] = {
{"ENGINE_VERSION_MAJOR", ENGINE_VERSION_MAJOR},
{"ENGINE_VERSION_MINOR", ENGINE_VERSION_MINOR},
{"BLOCK_AIR", BLOCK_AIR},
{"ITEM_EMPTY", ITEM_EMPTY},
{"CHUNK_W", CHUNK_W},
{"CHUNK_H", CHUNK_H},
{"CHUNK_D", CHUNK_D},
{"VOXEL_USER_BITS", VOXEL_USER_BITS},
{"VOXEL_USER_BITS_OFFSET", VOXEL_USER_BITS_OFFSET},
{"ITEM_ICON_SIZE", ITEM_ICON_SIZE},
{"CHUNK_VOL", CHUNK_VOL},
{"BLOCK_VOID", BLOCK_VOID},
{"ITEM_VOID", ITEM_VOID},
{"MAX_BLOCKS", MAX_BLOCKS}
};
for (const auto& constant : numberConstants) {
lua::pushnumber(L, constant.second);
lua::setfield(L, constant.first);
}
return 1;
}
const luaL_Reg corelib [] = {
{"new_world", lua::wrap<l_new_world>},
{"open_world", lua::wrap<l_open_world>},
@@ -172,5 +202,6 @@ const luaL_Reg corelib [] = {
{"quit", lua::wrap<l_quit>},
{"get_default_generator", lua::wrap<l_get_default_generator>},
{"get_generators", lua::wrap<l_get_generators>},
{"get_constants", lua::wrap<l_get_constants>},
{NULL, NULL}
};