Scarab
A thin, game-agnostic 2D engine host built on the sunlight tile-map engine
Loading...
Searching...
No Matches
luaengine.h
Go to the documentation of this file.
1/*
2 * Copyright (c) since 2021 by PopolonY2k and Leidson Campos A. Ferreira
3 *
4 * This software is provided 'as-is', without any express or implied
5 * warranty. In no event will the authors be held liable for any damages
6 * arising from the use of this software.
7 *
8 * Permission is granted to anyone to use this software for any purpose,
9 * including commercial applications, and to alter it and redistribute it
10 * freely, subject to the following restrictions:
11 *
12 * 1. The origin of this software must not be misrepresented; you must not
13 * claim that you wrote the original software. If you use this software
14 * in a product, an acknowledgment in the product documentation would be
15 * appreciated but is not required.
16 * 2. Altered source versions must be plainly marked as such, and must not be
17 * misrepresented as being the original software.
18 * 3. This notice may not be removed or altered from any source distribution.
19 */
20
21#ifndef __LUAENGINE_H__
22#define __LUAENGINE_H__
23
24extern "C"
25{
26 #include "lua.h"
27 #include "lualib.h"
28 #include "lauxlib.h"
29}
30
31#include "scripting/scriptprocessor.h"
32#include "lua/luaengineutil.h"
33#include <string>
34#include <cstdint>
35
36namespace SunLight {
37 namespace TileMap { class ITileMap; }
38 namespace Sound { class SoundManager; }
39}
40
41namespace Scarab {
42 namespace Engine {
43 class SpritePool;
44
45 namespace Lua { class LuaCollisionListener; }
46 }
47}
48
49namespace Scarab {
50 namespace Lua {
77 class LuaEngine {
78
79 lua_State *m_pLuaState;
80 SunLight :: Scripting :: ScriptProcessor *m_pScriptProcessor;
81 Engine :: Lua :: TimerMap m_Timers;
82 Engine :: Lua :: LuaCollisionListener *m_pCollisionListener;
83 std :: string m_strAppDirectory;
84
85 void RegisterCalls( void );
86
87 public:
88
89 LuaEngine( SunLight :: Scripting :: ScriptProcessor *pScriptProcessor );
90 virtual ~LuaEngine( void );
91
92 bool RunFile( std :: string strFileName );
93 void CallOnUpdate( uint32_t nDeltaMilli );
94 bool TryDispatchMoveSpritesToScreen( uint16_t nStateId );
95 bool TryDispatchLoadStage( uint16_t nStageId );
96 int GetActiveEnemyCount( void );
97 const std :: string& GetApplicationDirectory( void ) const;
98 void Init( Engine :: IRendererProvider *pRendererProvider,
99 SunLight :: Sound :: SoundManager *pSoundManager,
100 Engine :: SpritePool *pSpritePool );
101 void AttachToTileMap( SunLight :: TileMap :: ITileMap &tileMap );
102 void InstallVirtualClock( void );
103 };
104 }
105}
106#endif /* __LUAENGINE_H__ */
Implements a C++ abstraction for using Lua engine;.
Definition luaengine.h:77
int GetActiveEnemyCount(void)
Ask Lua how many enemies it currently has active, via the optional global get_active_enemy_count()....
Definition luaengine.cpp:266
bool RunFile(std ::string strFileName)
Execute a lua script - this is the ONE entry point that loads the game's very first script (EngineHos...
Definition luaengine.cpp:461
bool TryDispatchMoveSpritesToScreen(uint16_t nStateId)
Dispatch a MOVE_SPRITES_TO_SCREEN_CMD state id to Lua, via the optional global on_move_sprites_to_scr...
Definition luaengine.cpp:155
const std::string & GetApplicationDirectory(void) const
Return the running executable's own directory (also exposed to Lua as APP_DIR by Init above) - used b...
Definition luaengine.cpp:396
void AttachToTileMap(SunLight ::TileMap ::ITileMap &tileMap)
Attach the collision listener to a renderer's collision manager. Called by the renderer provider's cr...
Definition luaengine.cpp:369
void InstallVirtualClock(void)
Headless (–headless) only - make Lua's own os.time()/ os.clock() follow the null renderer's virtual c...
Definition luaengine.cpp:381
bool TryDispatchLoadStage(uint16_t nStageId)
Give Lua first refusal on a LOAD_STAGE_CMD state id, via the optional Lua global on_load_stage(stageI...
Definition luaengine.cpp:211
virtual ~LuaEngine(void)
Destructor. Finalize all class data;.
Definition luaengine.cpp:425
void CallOnUpdate(uint32_t nDeltaMilli)
Call the optional Lua on_update(dt) global once per frame, if defined. Absent global is a silent no-o...
Definition luaengine.cpp:105
void Init(Engine ::IRendererProvider *pRendererProvider, SunLight ::Sound ::SoundManager *pSoundManager, Engine ::SpritePool *pSpritePool)
Give Lua access to the renderer provider/SoundManager/SpritePool and register the primitive API modul...
Definition luaengine.cpp:313
Definition irendererprovider.h:32
Definition irendererprovider.h:27