ScummVM API documentation
luascript.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 /*
23  * This code is based on Broken Sword 2.5 engine
24  *
25  * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
26  *
27  * Licensed under GNU GPL v2
28  *
29  */
30 
31 #ifndef SWORD25_LUASCRIPT_H
32 #define SWORD25_LUASCRIPT_H
33 
34 #include "common/str.h"
35 #include "common/str-array.h"
36 #include "sword25/kernel/common.h"
37 #include "sword25/script/script.h"
38 
39 struct lua_State;
40 
41 namespace Sword25 {
42 
43 class Kernel;
44 
45 class LuaScriptEngine : public ScriptEngine {
46 public:
47  LuaScriptEngine(Kernel *KernelPtr);
48  ~LuaScriptEngine() override;
49 
54  bool init() override;
55 
61  bool executeFile(const Common::String &fileName) override;
62 
68  bool executeString(const Common::String &code) override;
69 
74  void *getScriptObject() override {
75  return _state;
76  }
77 
84  void setCommandLine(const Common::StringArray &commandLineParameters) override;
85 
89  bool persist(OutputPersistenceBlock &writer) override;
93  bool unpersist(InputPersistenceBlock &reader) override;
94 
95 private:
96  lua_State *_state;
97  int _pcallErrorhandlerRegistryIndex;
98 
99  bool registerStandardLibs();
100  bool registerStandardLibExtensions();
101  bool executeBuffer(const byte *data, uint size, const Common::String &name) const;
102 };
103 
104 } // End of namespace Sword25
105 
106 #endif
bool executeString(const Common::String &code) override
Definition: str.h:59
void setCommandLine(const Common::StringArray &commandLineParameters) override
void * getScriptObject() override
Definition: luascript.h:74
Definition: script.h:46
Definition: lstate.h:100
bool executeFile(const Common::String &fileName) override
Definition: console.h:27
Definition: kernel.h:72
Definition: luascript.h:45
bool persist(OutputPersistenceBlock &writer) override
Definition: inputpersistenceblock.h:40
bool init() override
bool unpersist(InputPersistenceBlock &reader) override
Definition: outputpersistenceblock.h:39