mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-05 02:51:49 +00:00
lua api refactor
This commit is contained in:
parent
5309cbe67f
commit
6bf6e8e011
20 changed files with 663 additions and 710 deletions
|
|
@ -1,4 +1,5 @@
|
|||
#include "libhud.h"
|
||||
#include "lua_commons.h"
|
||||
#include "api_lua.h"
|
||||
#include "LuaState.h"
|
||||
|
||||
#include <iostream>
|
||||
|
|
@ -22,21 +23,21 @@ namespace scripting {
|
|||
extern Hud* hud;
|
||||
}
|
||||
|
||||
int l_hud_open_inventory(lua_State* L) {
|
||||
static int l_hud_open_inventory(lua_State* L) {
|
||||
if (!scripting::hud->isInventoryOpen()) {
|
||||
scripting::hud->openInventory();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int l_hud_close_inventory(lua_State* L) {
|
||||
static int l_hud_close_inventory(lua_State* L) {
|
||||
if (scripting::hud->isInventoryOpen()) {
|
||||
scripting::hud->closeInventory();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int l_hud_open_block(lua_State* L) {
|
||||
static int l_hud_open_block(lua_State* L) {
|
||||
lua::luaint x = lua_tointeger(L, 1);
|
||||
lua::luaint y = lua_tointeger(L, 2);
|
||||
lua::luaint z = lua_tointeger(L, 3);
|
||||
|
|
@ -64,7 +65,7 @@ int l_hud_open_block(lua_State* L) {
|
|||
return 2;
|
||||
}
|
||||
|
||||
UiDocument* require_layout(lua_State* L, const char* name) {
|
||||
static UiDocument* require_layout(lua_State* L, const char* name) {
|
||||
auto assets = scripting::engine->getAssets();
|
||||
auto layout = assets->getLayout(name);
|
||||
if (layout == nullptr) {
|
||||
|
|
@ -73,14 +74,23 @@ UiDocument* require_layout(lua_State* L, const char* name) {
|
|||
return layout;
|
||||
}
|
||||
|
||||
int l_hud_open_permanent(lua_State* L) {
|
||||
static int l_hud_open_permanent(lua_State* L) {
|
||||
auto layout = require_layout(L, lua_tostring(L, 1));
|
||||
scripting::hud->openPermanent(layout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int l_hud_close(lua_State* L) {
|
||||
static int l_hud_close(lua_State* L) {
|
||||
auto layout = require_layout(L, lua_tostring(L, 1));
|
||||
scripting::hud->remove(layout->getRoot());
|
||||
return 0;
|
||||
}
|
||||
|
||||
const luaL_Reg hudlib [] = {
|
||||
{"open_inventory", lua_wrap_errors<l_hud_open_inventory>},
|
||||
{"close_inventory", lua_wrap_errors<l_hud_close_inventory>},
|
||||
{"open_block", lua_wrap_errors<l_hud_open_block>},
|
||||
{"open_permanent", lua_wrap_errors<l_hud_open_permanent>},
|
||||
{"close", lua_wrap_errors<l_hud_close>},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue