]> git.r.bdr.sh - rbdr/pico-engine/blob - LuaVirtualMachine.h
61cf65b07e0c14b28bf159f7fb241513474e0ff6
[rbdr/pico-engine] / LuaVirtualMachine.h
1 // ---------------------------------------------------------------------------
2 // FILE NAME : LuaVirtualMachine.h
3 // ---------------------------------------------------------------------------
4 // DESCRIPTION :
5 //
6 // Lua virtual machine implementation
7 //
8 // ---------------------------------------------------------------------------
9 // VERSION : 1.00
10 // DATE : 1-Sep-2005
11 // AUTHOR : Richard Shephard
12 // ---------------------------------------------------------------------------
13 // LIBRARY INCLUDE FILES
14 #ifndef __LUA_VIRTUAL_MACHINE_H__
15 #define __LUA_VIRTUAL_MACHINE_H__
16
17 #include "luainc.h"
18 #include "luadebugger.h"
19
20 class CLuaDebugger;
21
22 class CLuaVirtualMachine
23 {
24 public:
25 CLuaVirtualMachine (void);
26 virtual ~CLuaVirtualMachine (void);
27
28 bool InitialiseVM (void);
29 bool DestroyVM (void);
30
31 // Load and run script elements
32 bool RunFile (const char *strFilename);
33 bool RunBuffer (const unsigned char *pbBuffer, size_t szLen, const char *strName = NULL);
34
35 // C-Api into script
36 bool CallFunction (int nArgs, int nReturns = 0);
37
38 // Get the state of the lua stack (use the cast operator)
39 //lua_State *GetState (void) { return m_pState; }
40 operator lua_State *(void) { return m_pState; }
41
42 static void Panic (lua_State *lua);
43
44 // Check if the VM is OK and can be used still
45 virtual bool Ok (void) { return m_fIsOk; }
46
47 // For debugging
48 void AttachDebugger (CLuaDebugger *dbg) { m_pDbg = dbg; }
49
50 protected:
51 lua_State *m_pState;
52 bool m_fIsOk;
53 CLuaDebugger *m_pDbg;
54 };
55
56
57 #endif // __LUA_VIRTUAL_MACHINE_H__