ScummVM API documentation
lua.h
1 /*
2 ** Lua - An Extensible Extension Language
3 ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
4 ** e-mail: lua@tecgraf.puc-rio.br
5 ** www: http://www.tecgraf.puc-rio.br/lua/
6 ** See Copyright Notice at the end of this file
7 */
8 
9 #ifndef GRIM_LUA_H
10 #define GRIM_LUA_H
11 
12 #include "common/scummsys.h"
13 #include "common/str.h"
14 
15 namespace Common {
16  class String;
17  class SeekableReadStream;
18  class WriteStream;
19  class File;
20 }
21 
22 namespace Grim {
23 
24 #define LUA_VERSION "Lua 3.1 (alpha)"
25 #define LUA_COPYRIGHT "Copyright (C) 1994-1998 TeCGraf, PUC-Rio"
26 #define LUA_AUTHORS "W. Celes, R. Ierusalimschy & L. H. de Figueiredo"
27 
28 #define LUA_NOOBJECT 0
29 
30 #define LUA_ANYTAG (-1)
31 
32 typedef void (*lua_CFunction)();
33 typedef uint32 lua_Object;
34 
35 struct PointerId {
36  uint64 id;
37 };
38 
39 PointerId makeIdFromPointer(void *ptr);
40 void *makePointerFromId(PointerId ptr);
41 
42 class LuaFile {
43 public:
44  Common::String _name;
45  Common::String _filename;
47  Common::WriteStream *_out;
48  bool _stdin, _stdout, _stderr;
49 
50 public:
51  LuaFile();
52  ~LuaFile();
53 
54  void close();
55  bool isOpen() const;
56  uint32 read(void *buf, uint32 len);
57  uint32 write(const char *buf, uint32 len);
58  void seek(int32 pos, int whence = 0);
59 };
60 
61 class SaveGame;
62 void lua_Save(SaveGame *state);
63 void lua_Restore(SaveGame *state);
64 
65 void lua_removelibslists();
66 
67 void lua_open();
68 void lua_close();
69 bool lua_isopen();
70 
71 lua_Object lua_settagmethod(int32 tag, const char *event); // In: new method
72 lua_Object lua_gettagmethod(int32 tag, const char *event);
73 lua_Object lua_seterrormethod(); // In: new method
74 
75 int32 lua_newtag();
76 int32 lua_copytagmethods(int32 tagto, int32 tagfrom);
77 void lua_settag(int32 tag); // In: object
78 
79 void lua_error(const char *s);
80 int32 lua_dostring(const char *string); // Out: returns
81 int32 lua_dobuffer(const char *buff, int32 size, const char *name);
82 int32 lua_callfunction(lua_Object f);
83 // In: parameters; Out: returns */
84 
85 void lua_beginblock();
86 void lua_endblock();
87 
88 lua_Object lua_lua2C(int32 number);
89 
90 #define lua_getparam(_) lua_lua2C(_)
91 #define lua_getresult(_) lua_lua2C(_)
92 
93 int32 lua_isnil (lua_Object object);
94 int32 lua_istable (lua_Object object);
95 int32 lua_isuserdata (lua_Object object);
96 int32 lua_iscfunction (lua_Object object);
97 int32 lua_isnumber (lua_Object object);
98 int32 lua_isstring (lua_Object object);
99 int32 lua_isfunction (lua_Object object);
100 
101 float lua_getnumber (lua_Object object);
102 const char *lua_getstring (lua_Object object);
103 lua_CFunction lua_getcfunction (lua_Object object);
104 int32 lua_getuserdata (lua_Object object);
105 
106 void lua_pushnil();
107 void lua_pushnumber(float n);
108 void lua_pushstring(const char *s);
109 void lua_pushCclosure(lua_CFunction fn, int32 n);
110 void lua_pushusertag(int32 id, int32 tag);
111 void lua_pushobject(lua_Object object);
112 
113 lua_Object lua_pop();
114 lua_Object lua_getglobal(const char *name);
115 lua_Object lua_rawgetglobal(const char *name);
116 void lua_setglobal(const char *name); // In: value
117 void lua_rawsetglobal(const char *name); // In: value
118 
119 void lua_settable(); // In: table, index, value
120 void lua_rawsettable(); // In: table, index, value
121 lua_Object lua_gettable(); // In: table, index
122 lua_Object lua_rawgettable(); // In: table, index
123 
124 int32 lua_tag(lua_Object object);
125 
126 int32 lua_ref(int32 lock); // In: value
127 lua_Object lua_getref(int32 ref);
128 void lua_unref(int32 ref);
129 
130 lua_Object lua_createtable();
131 int32 lua_collectgarbage(int32 limit);
132 
133 void lua_runtasks();
134 void current_script();
135 
136 /* some useful macros/derived functions */
137 
138 #define lua_call(name) lua_callfunction(lua_getglobal(name))
139 
140 #define lua_pushref(ref) lua_pushobject(lua_getref(ref))
141 
142 #define lua_refobject(o,l) (lua_pushobject(o), lua_ref(l))
143 
144 #define lua_register(n, f) (lua_pushcfunction(f), lua_setglobal(n))
145 
146 #define lua_pushuserdata(u) lua_pushusertag(u, 0)
147 
148 #define lua_pushcfunction(f) lua_pushCclosure(f, 0)
149 
150 #define lua_clonetag(t) lua_copytagmethods(lua_newtag(), (t))
151 
152 /* ==========================================================================
153 ** for compatibility with old versions. Avoid using these macros/functions
154 ** If your program does need any of these, define LUA_COMPAT2_5
155 */
156 #define LUA_COMPAT2_5
157 
158 #ifdef LUA_COMPAT2_5
159 
160 lua_Object lua_setfallback(const char *event, lua_CFunction fallback);
161 
162 #define lua_storeglobal lua_setglobal
163 #define lua_type lua_tag
164 
165 #define lua_lockobject(o) lua_refobject(o,1)
166 #define lua_lock() lua_ref(1)
167 #define lua_getlocked lua_getref
168 #define lua_pushlocked lua_pushref
169 #define lua_unlock lua_unref
170 #define lua_pushliteral(o) lua_pushstring(o)
171 #define lua_getindexed(o, n) (lua_pushobject(o), lua_pushnumber(n), lua_gettable())
172 #define lua_getfield(o, f) (lua_pushobject(o), lua_pushstring(f), lua_gettable())
173 #define lua_copystring(o) (strdup(lua_getstring(o)))
174 #define lua_getsubscript lua_gettable
175 #define lua_storesubscript lua_settable
176 
177 #endif
178 
179 
180 /******************************************************************************
181 * Copyright (c) 1994-1998 TeCGraf, PUC-Rio. All rights reserved.
182 *
183 * Permission is hereby granted, without written agreement and without license
184 * or royalty fees, to use, copy, modify, and distribute this software and its
185 * documentation for any purpose, including commercial applications, subject to
186 * the following conditions:
187 *
188 * - The above copyright notice and this permission notice shall appear in all
189 * copies or substantial portions of this software.
190 *
191 * - The origin of this software must not be misrepresented; you must not
192 * claim that you wrote the original software. If you use this software in a
193 * product, an acknowledgment in the product documentation would be greatly
194 * appreciated (but it is not required).
195 *
196 * - Altered source versions must be plainly marked as such, and must not be
197 * misrepresented as being the original software.
198 *
199 * The authors specifically disclaim any warranties, including, but not limited
200 * to, the implied warranties of merchantability and fitness for a particular
201 * purpose. The software provided hereunder is on an "as is" basis, and the
202 * authors have no obligation to provide maintenance, support, updates,
203 * enhancements, or modifications. In no event shall TeCGraf, PUC-Rio, or the
204 * authors be held liable to any party for direct, indirect, special,
205 * incidental, or consequential damages arising out of the use of this software
206 * and its documentation.
207 *
208 * The Lua language and this implementation have been entirely designed and
209 * written by Waldemar Celes Filho, Roberto Ierusalimschy and
210 * Luiz Henrique de Figueiredo at TeCGraf, PUC-Rio.
211 *
212 * NOTE: This implementation of Lua contains additional code and
213 * modifications added only for ScummVM project.
214 * Look into the source code file "Changelog" for more info.
215 ******************************************************************************/
216 
217 } // end of namespace Grim
218 
219 #endif
Definition: str.h:59
Definition: stream.h:77
Definition: lua.h:35
Definition: lstate.h:56
Definition: savegame.h:33
Definition: stream.h:745
Definition: actor.h:33
Definition: lua.h:42
Definition: algorithm.h:29