Debian Codegraph @

engine/include/script.h

raw
1 // ____ _ __
2 // / __ )____ _____ | | / /___ ___________
3 // / __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/
4 // / /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ )
5 // /_____/\____/____/ |__/|__/\__,_/_/ /____/
6 //
7 // A futuristic real-time strategy game.
8 // This file is part of Bos Wars.
9 //
10 /**@name script.h - The configuration language headerfile. */
11 //
12 // (c) Copyright 1998-2008 by Lutz Sammer and Jimmy Salmon
13 //
14 // This program is free software; you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation; only version 2 of the License.
17 //
18 // This program is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU General Public License for more details.
22 //
23 // You should have received a copy of the GNU General Public License
24 // along with this program; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 // 02111-1307, USA.
27
28 #ifndef __SCRIPT_H__
29 #define __SCRIPT_H__
30
31 //@{
32
33 /*----------------------------------------------------------------------------
34 -- Includes
35 ----------------------------------------------------------------------------*/
36
37 #include <string>
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 #include "lua.h"
43 #include "lauxlib.h"
44 #include "lualib.h"
45 #ifdef __cplusplus
46 }
47 #endif
48
49 /*----------------------------------------------------------------------------
50 -- Declarations
51 ----------------------------------------------------------------------------*/
52
53 class CFile;
54
55 typedef struct _lua_user_data_ {
56 int Type;
57 void *Data;
58 } LuaUserData;
59
60 enum {
61 LuaUnitType = 100,
62 LuaSoundType,
63 };
64
65 extern lua_State *Lua;
66
67 extern int LuaLoadFile(const std::string &file);
68 extern int LuaCall(int narg, int clear, bool exitOnError = true);
69
70 #define LuaError(l, args) \
71 do { \
72 fprintf(stdout, "%s:%d: ", __FILE__, __LINE__); \
73 fprintf(stdout, args); \
74 fprintf(stdout, "\n"); \
75 lua_pushfstring(l, args); lua_error(l); \
76 } while (0)
77
78 #define LuaCheckArgs(l, args) \
79 do { \
80 if (lua_gettop(l) != args) { \
81 LuaError(l, "incorrect argument"); \
82 } \
83 } while (0)
84
85 #define LuaCheckTable(l, index) \
86 do { \
87 if (!lua_istable((l), (index))) { \
88 LuaError(l, "incorrect argument"); \
89 } \
90 } while (0)
91
92 #define LuaCheckTableSize(l, index, size) \
93 do { \
94 if (!lua_istable((l), (index)) || lua_objlen((l), (index)) != (size)) { \
95 LuaError(l, "incorrect argument"); \
96 } \
97 } while (0)
98
99 /*----------------------------------------------------------------------------
100 -- Variables
101 ----------------------------------------------------------------------------*/
102
103 extern std::string CclStartFile; /// CCL start file
104 extern int CclInConfigFile; /// True while config file parsing
105
106 /*----------------------------------------------------------------------------
107 -- Functions
108 ----------------------------------------------------------------------------*/
109
110 extern const char *LuaToString(lua_State *l, int index);
111 extern const char *LuaToString(lua_State *l, int tableIndex, int stringIndex);
112 extern int LuaToNumber(lua_State *l, int index);
113 extern int LuaToNumber(lua_State *l, int tableIndex, int numberIndex);
114 extern bool LuaToBoolean(lua_State *l, int index);
115 extern int luatraceback(lua_State *L);
116
117 extern void CclGarbageCollect(int fast); /// Perform garbage collection
118 extern void InitCcl(void); /// Initialise ccl
119 extern void LoadCcl(void); /// Load ccl config file
120 extern void SaveCcl(CFile *file); /// Save CCL module
121 extern void SavePreferences(void); /// Save user preferences
122 extern char *SaveGlobal(lua_State *l, bool is_root); /// For saving lua state
123 extern int CclCommand(const std::string &command, bool exitOnError = true); /// Execute a ccl command
124
125 //@}
126
127 #endif // !__SCRIPT_H__