lua: hud library

This commit is contained in:
MihailRis
2024-02-16 13:57:03 +03:00
parent ffed4319da
commit 7e553efdec
14 changed files with 140 additions and 31 deletions
+20
View File
@@ -0,0 +1,20 @@
#include "libhud.h"
#include <iostream>
#include "../scripting.h"
#include "../../../frontend/hud.h"
namespace scripting {
extern Hud* hud;
}
int l_hud_open_inventory(lua_State* L) {
scripting::hud->openInventory();
return 0;
}
int l_hud_close_inventory(lua_State* L) {
scripting::hud->closeInventory();
return 0;
}
+15
View File
@@ -0,0 +1,15 @@
#ifndef LOGIC_SCRIPTING_API_LIBHUD_H_
#define LOGIC_SCRIPTING_API_LIBHUD_H_
#include <lua.hpp>
extern int l_hud_open_inventory(lua_State* L);
extern int l_hud_close_inventory(lua_State* L);
static const luaL_Reg hudlib [] = {
{"open_inventory", l_hud_open_inventory},
{"close_inventory", l_hud_close_inventory},
{NULL, NULL}
};
#endif // LOGIC_SCRIPTING_API_LIBHUD_H_
-2
View File
@@ -7,8 +7,6 @@
namespace fs = std::filesystem;
class LuaState;
class Engine;
class Content;
struct ContentPack;
@@ -0,0 +1,16 @@
#include "scripting_frontend.h"
#include "scripting.h"
#include "api/libhud.h"
#include "LuaState.h"
namespace scripting {
extern lua::LuaState* state;
}
Hud* scripting::hud = nullptr;
void scripting::on_frontend_init(Hud* hud) {
scripting::hud = hud;
scripting::state->openlib("hud", hudlib, 0);
}
+12
View File
@@ -0,0 +1,12 @@
#ifndef LOGIC_SCRIPTING_SCRIPTING_FRONTEND_H_
#define LOGIC_SCRIPTING_SCRIPTING_FRONTEND_H_
class Hud;
namespace scripting {
extern Hud* hud;
void on_frontend_init(Hud* hud);
}
#endif // LOGIC_SCRIPTING_SCRIPTING_FRONTEND_H_