FS2_Open
Open source remastering of the Freespace 2 engine
lua.h
Go to the documentation of this file.
1 #ifndef _LUA_H
2 #define _LUA_H
3 
4 extern "C" {
5  #include <lauxlib.h>
6  #include <lualib.h>
7 }
8 
9 #include "globalincs/pstypes.h"
10 #include "menuui/mainhallmenu.h"
11 #include "object/object.h"
12 
13 //*************************Lua funcs*************************
14 //Used to parse arguments on the stack to C values
15 int ade_get_args(lua_State *L, const char *fmt, ...);
16 int ade_set_args(lua_State *L, const char *fmt, ...);
17 void ade_stackdump(lua_State *L, char *stackdump);
18 int ade_friendly_error(lua_State *L);
19 
20 //*************************Lua hacks*************************
21 //WMC - Hack to allow for quick&easy return value parsing
22 extern int Ade_get_args_skip;
23 //WMC - Tell ade_get_args it is parsing lua functions,
24 //which have no upvalues
25 extern bool Ade_get_args_lfunction;
26 
27 //*************************Lua types*************************
28 
29 //WMC - Define to say that this is to store just a pointer.
30 #define ODATA_PTR_SIZE -1
31 #define ODATA_SIG_TYPE uint //WMC - Please don't touch.
32 #define ODATA_SIG_DEFAULT 0
33 
38 struct ade_odata
39 {
40  //ade_id aid;
43  void *buf;
44  int size;
45  //ade_odata(){idx=UINT_MAX;sig=NULL;buf=NULL;size=0;}
46 /*
47  ade_odata &operator =(const ade_odata &slo) {
48  aid = slo.aid;
49  buf = slo.buf;
50  size = slo.size;
51 
52  return (*this);
53  }*/
54 };
55 
56 //WMC - 'Type' is the same as ade_set_args,
57 //plus some extra
58 //b - boolean
59 //d - double
60 //f - float
61 //i - integer
62 //s - string
63 //x - fix
64 //o - object
65 //EXTRA:
66 //l - library //WMC - no longer exists
67 //u - function
68 //v - virtual variable
69 //
70 //u - oh wait...
71 
72 #define ADE_INDEX(ate) (ate - &Ade_table_entries[0])
73 
75 
77 {
78 public:
79  char *Name;
80  char *ShortName;
81 
82  //Important stuff
85  //ade_id AdeID;
86  //ade_id DerivatorID; //Who do we derive from
87 
88  //Type-specific
89  bool Instanced; //Is this a single instance?
90  char Type;
91  union {
92  //Variables
93  bool varBool;
94  double varDouble;
95  float varFloat;
96  int varInt;
97  char *varString;
98 
99  //Functions/virtfuncs
100  lua_CFunction Function;
101 
102  //Objects
104  } Value;
105  size_t Size;
106 
107  //Metadata
108  char *Arguments;
109  char *Description;
110  char *ReturnType;
112 
113  //Subentries, of course
114  //WMC - I have HAD it with these motherfriendly vectors
115  //on this motherfriendly class.
118 
119 private:
120  //*****Internal functions
121  //int IndexHandler(lua_State *L);
122 
123 public:
124  //*****Constructors
125  ade_table_entry() : Name(NULL), ShortName(NULL), ParentIdx(UINT_MAX), DerivatorIdx(UINT_MAX), Instanced(false),
126  Size(0), Arguments(NULL), Description(NULL), ReturnType(NULL), ReturnDescription(NULL), Num_subentries(0)
127  {
128  Type = '\0';
129  memset(Subentries, 0, sizeof(Subentries));
130  }
131 
132  //*****Operators
133  //ade_table_entry &operator = (const ade_table_entry &ate);
134 
135  //*****Functions
137  {
138  ade_table_entry ate = n_ate;
139  ate.ParentIdx = ADE_INDEX(this);
140  Ade_table_entries.push_back(ate);
141  uint new_idx = Ade_table_entries.size()-1;
142 
143  //WMC - Oi. Moving the Ade_table_entries vector
144  //invalidates the "this" pointer. Workaround time.
145  ade_table_entry *new_this = &Ade_table_entries[ate.ParentIdx];
146  uint idx = new_this->Num_subentries++;
147  new_this->Subentries[idx] = new_idx;
148 
149  return new_idx;
150  }
151  int SetTable(lua_State *L, int p_amt_ldx, int p_mtb_ldx);
152  void OutputMeta(FILE *fp);
153 
154  //*****Get
155  char *GetName(){if(Name!=NULL)return Name;else return ShortName;}
156 };
157 
159 {
160 protected:
161  //ade_id LibAID;
163 public:
165 /*
166  void AddEntry(ade_table_entry &in_ate) {
167  Ade_table_entries[LibIdx].AddSubentry(in_ate);
168  }
169 */
171  return LibIdx;
172  }
173 };
174 
175 //Object class
176 //This is what you define a variable of to make new objects
177 template <class StoreType> class ade_obj : public ade_lib_handle
178 {
179 public:
180  ade_obj(char*in_name, char*in_desc, ade_lib_handle* in_deriv=NULL)
181  {
182  ade_table_entry ate;
183 
184  //WMC - object metadata are uninstanced library types
185  ate.Name = in_name;
186  if(in_deriv != NULL)
187  ate.DerivatorIdx = in_deriv->GetIdx();
188  ate.Type = 'o';
189  ate.Description = in_desc;
190  ate.Value.Object.idx = Ade_table_entries.size();
191  ate.Value.Object.sig = NULL;
192  ate.Value.Object.size = sizeof(StoreType);
193 
194  Ade_table_entries.push_back(ate);
195  LibIdx = Ade_table_entries.size() - 1;
196  }
197 
198  //WMC - Use this to store object data for return, or for setting as a global
199  ade_odata Set(const StoreType &obj, ODATA_SIG_TYPE n_sig=ODATA_SIG_DEFAULT) {
200  ade_odata od;
201  od.idx = LibIdx;
202  od.sig = (uint*)&n_sig;
203  od.buf = (void*)&obj;
204  od.size = sizeof(StoreType);
205  return od;
206  }
207 
208  //WMC - Use this to copy object data, for modification or whatever
209  ade_odata Get(StoreType *ptr, uint *n_sig=NULL){
210  ade_odata od;
211  od.idx = LibIdx;
212  od.sig = n_sig;
213  od.buf = ptr;
214  od.size = sizeof(StoreType);
215  return od;
216  }
217 
218  //WMC - Use this to get a pointer to Lua object data.
219  //Use >ONLY< when:
220  //1 - You are setting the data of an object (ie 'x' component of vector)
221  //2 - To speed up read-only calcs (ie computing dot product of vectors)
222  ade_odata GetPtr(StoreType **ptr){
223  ade_odata od;
224  od.idx = LibIdx;
225  od.sig = NULL;
226  od.buf = (void**)ptr;
227  od.size = -1;
228  return od;
229  }
230 };
231 
232 //*************************Lua global structs*************************
233 
234 
235 //*************************Lua globals*************************
241 
242 #endif //_LUA_H
SCP_vector< class ade_table_entry > Ade_table_entries
Definition: lua.cpp:61
uint GetIdx()
Definition: lua.h:170
uint AddSubentry(ade_table_entry &n_ate)
Definition: lua.h:136
Definition: lua.h:76
uint ParentIdx
Definition: lua.h:83
ade_obj< object_h > l_Debris
uint Subentries[256]
Definition: lua.h:117
void ade_stackdump(lua_State *L, char *stackdump)
Definition: lua.cpp:15953
int ade_friendly_error(lua_State *L)
Definition: lua.cpp:16392
ade_obj(char *in_name, char *in_desc, ade_lib_handle *in_deriv=NULL)
Definition: lua.h:180
double varDouble
Definition: lua.h:94
#define ADE_INDEX(ate)
Definition: lua.h:72
ade_odata Object
Definition: lua.h:103
ade_obj< object_h > l_Object
char * Arguments
Definition: lua.h:108
char * ReturnType
Definition: lua.h:110
unsigned int uint
Definition: pstypes.h:64
union ade_table_entry::@260 Value
ade_odata Set(const StoreType &obj, ODATA_SIG_TYPE n_sig=ODATA_SIG_DEFAULT)
Definition: lua.h:199
Definition: lua.h:38
ade_odata Get(StoreType *ptr, uint *n_sig=NULL)
Definition: lua.h:209
int idx
Definition: multiui.cpp:761
ade_obj< object_h > l_Ship
cfbp fp
Definition: cfile.cpp:1065
ade_obj< object_h > l_Asteroid
char Type
Definition: lua.h:90
bool Ade_get_args_lfunction
Definition: lua.cpp:16098
size_t Size
Definition: lua.h:105
int ade_set_args(lua_State *L, const char *fmt,...)
Definition: lua.cpp:16313
void OutputMeta(FILE *fp)
Definition: lua.cpp:16875
void * buf
Definition: lua.h:43
ade_lib_handle()
Definition: lua.h:164
ODATA_SIG_TYPE * sig
Definition: lua.h:42
char * ReturnDescription
Definition: lua.h:111
#define ODATA_SIG_TYPE
Definition: lua.h:31
ade_odata GetPtr(StoreType **ptr)
Definition: lua.h:222
int Ade_get_args_skip
Definition: lua.cpp:16097
uint Num_subentries
Definition: lua.h:116
char * GetName()
Definition: lua.h:155
int ade_get_args(lua_State *L, const char *fmt,...)
Definition: lua.cpp:16113
bool varBool
Definition: lua.h:93
int SetTable(lua_State *L, int p_amt_ldx, int p_mtb_ldx)
Definition: lua.cpp:16663
uint idx
Definition: lua.h:41
#define ODATA_SIG_DEFAULT
Definition: lua.h:32
Definition: lua.h:177
GLsizei GLsizei GLuint * obj
Definition: Glext.h:5619
bool Instanced
Definition: lua.h:89
ade_table_entry()
Definition: lua.h:125
lua_CFunction Function
Definition: lua.h:100
char * varString
Definition: lua.h:97
uint LibIdx
Definition: lua.h:162
ade_obj< object_h > l_Weapon
char * Description
Definition: lua.h:109
int size
Definition: lua.h:44
char * Name
Definition: lua.h:79
uint DerivatorIdx
Definition: lua.h:84
false
Definition: lua.cpp:6789
int varInt
Definition: lua.h:96
float varFloat
Definition: lua.h:95
char * ShortName
Definition: lua.h:80