Just™ Game Engine
lua_engine.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022 Konstanty Misiak
3 *
4 * SPDX-License-Identifier: MIT
5 */
6
7#pragma once
8#include <jng/core/base.hpp>
10
11class lua_State;
12
13namespace jng {
14
15 struct LuaScriptComponent;
16
17 namespace LuaEngine {
18
20 {
21 enum class PropertyType
22 {
23 Number = 0
24 };
25
26 struct Property
27 {
29 void* value;
30 };
31
32 bool hasOnCreate = false;
33 bool hasOnDestroy = false;
34 bool hasOnUpdate = false;
35
36 using PropertiesContainerType = std::map<std::string, Property>;
38 };
39
40 void init();
41 void shutdown();
42
43 std::string registerScript(const std::filesystem::path& path);
44 void unregisterScripts();
45 ScriptData getScriptData(const std::string& name);
46
47 void onCreate(Entity entity, LuaScriptComponent& lsc);
48 void onDestroy(Entity entity, LuaScriptComponent& lsc);
49 void onUpdate(Entity entity, LuaScriptComponent& lsc, float dt);
50
51 void printLuaStack(const char* file, int line);
52
53 } // namespace LuaEngine
54
55} // namespace jng
56
57#ifdef JNG_DEBUG
58#define JNG_PRINT_LUA_STACK() jng::LuaEngine::printLuaStack(__FILE__, __LINE__)
59#else
60#define JNG_PRINT_LUA_STACK()
61#endif
Definition: entity.hpp:17
void shutdown()
Definition: lua_engine.cpp:154
ScriptData getScriptData(const std::string &name)
Definition: lua_engine.cpp:216
std::string registerScript(const std::filesystem::path &path)
Definition: lua_engine.cpp:159
void init()
Definition: lua_engine.cpp:138
void onUpdate(Entity entity, LuaScriptComponent &lsc, float dt)
Definition: lua_engine.cpp:329
void onDestroy(Entity entity, LuaScriptComponent &lsc)
Definition: lua_engine.cpp:296
void unregisterScripts()
Definition: lua_engine.cpp:211
void onCreate(Entity entity, LuaScriptComponent &lsc)
Definition: lua_engine.cpp:265
void printLuaStack(const char *file, int line)
Definition: lua_engine.cpp:357
Definition: base.hpp:11
Definition: lua_engine.hpp:27
void * value
Definition: lua_engine.hpp:29
PropertyType type
Definition: lua_engine.hpp:28
Definition: lua_engine.hpp:20
bool hasOnDestroy
Definition: lua_engine.hpp:33
PropertyType
Definition: lua_engine.hpp:22
std::map< std::string, Property > PropertiesContainerType
Definition: lua_engine.hpp:36
PropertiesContainerType properties
Definition: lua_engine.hpp:37
bool hasOnCreate
Definition: lua_engine.hpp:32
bool hasOnUpdate
Definition: lua_engine.hpp:34
Definition: components.hpp:150