1 // ----------------------------------------------------------------------------
2 // Overridden functions for the wxWidgets binding for wxLua
3 //
4 // Please keep these functions in the same order as the .i file and in the
5 // same order as the listing of the functions in that file.
6 // ----------------------------------------------------------------------------
7 
8 // ----------------------------------------------------------------------------
9 // Overrides for wxbase_base.i
10 // ----------------------------------------------------------------------------
11 
12 %override wxLua_wxLog_SetTimestamp
13 //     static void SetTimestamp(const wxString& ts)
14 static int LUACALL wxLua_wxLog_SetTimestamp(lua_State *L)
15 {
16     // docs say that using NULL will disable time stamping. The actual arg is "const wxChar* ts"
17     if (lua_isnoneornil(L, 1))
18     {
19 #if wxCHECK_VERSION(2, 9, 0)
20         wxLog::SetTimestamp(wxEmptyString);
21 #else
22         wxLog::SetTimestamp(NULL);
23 #endif
24     }
25     else
26     {
27         // const wxString ts
28         const wxString ts = wxlua_getwxStringtype(L, 1);
29         // call SetTimestamp
30         wxLog::SetTimestamp(ts);
31     }
32 
33     return 0;
34 }
35 %end
36 
37 %override wxLua_function_wxGetOsVersion
38 // %function int wxGetOsVersion(int *major = NULL, int *minor = NULL)
39 static int LUACALL wxLua_function_wxGetOsVersion(lua_State *L)
40 {
41     // int *minor = NULL
42     int minor= 0;
43     // int *major = NULL
44     int major = 0;
45     // call wxGetOsVersion
46     int returns = wxGetOsVersion(&major, &minor);
47     // push the result numbers
48     lua_pushinteger(L, returns);
49     lua_pushinteger(L, major);
50     lua_pushinteger(L, minor);
51     // return the number of parameters
52     return 3;
53 }
54 %end
55 
56 %override wxLua_function_wxGetEnv
57 // %function bool wxGetEnv(const wxString& var, wxString *value)
58 static int LUACALL wxLua_function_wxGetEnv(lua_State *L)
59 {
60     wxString var = wxlua_getwxStringtype(L, 1);
61     wxString value;
62     // call wxGetEnv
63     bool returns = wxGetEnv(var, &value);
64     // push the result number
65     lua_pushboolean(L, returns);
66     wxlua_pushwxString(L, value);
67     // return the number of parameters
68     return 2;
69 }
70 %end
71 
72 %override wxLua_wxStandardPaths_Get
73 //     static wxStandardPaths& Get();
74 static int LUACALL wxLua_wxStandardPaths_Get(lua_State *L)
75 {
76     // call Get
77     wxStandardPathsBase *returns = &wxStandardPaths::Get();
78     // push the result datatype
79     wxluaT_pushuserdatatype(L, returns, wxluatype_wxStandardPaths);
80 
81     return 1;
82 }
83 %end
84 
85 %override wxLua_wxRegEx_GetMatchIndexes
86 // %rename GetMatchPointer bool GetMatch(size_t* start, size_t* len, size_t index = 0) const
87 static int LUACALL wxLua_wxRegEx_GetMatchIndexes(lua_State *L)
88 {
89     // get number of arguments
90     int argCount = lua_gettop(L);
91     // size_t index = 0
92     size_t index = (argCount >= 2 ? (size_t)wxlua_getintegertype(L, 2) : 0);
93     // size_t* len
94     size_t len = 0;
95     // size_t* start
96     size_t start = 0;
97     // get this
98     wxRegEx *self = (wxRegEx *)wxluaT_getuserdatatype(L, 1, wxluatype_wxRegEx);
99     // call GetMatch
100     bool returns = self->GetMatch(&start, &len, index);
101     // push the result number
102     lua_pushboolean(L, returns);
103     // push the match start and length indexes
104     lua_pushinteger(L, start);
105     lua_pushinteger(L, len);
106     // return the number of parameters
107     return 3;
108 }
109 %end
110 
111 %override wxLua_wxRegEx_Replace
112 // int Replace(wxString* text, const wxString& replacement, size_t maxMatches = 0) const
113 static int LUACALL wxLua_wxRegEx_Replace(lua_State *L)
114 {
115     // get number of arguments
116     int argCount = lua_gettop(L);
117     // size_t maxMatches = 0
118     size_t maxMatches = (argCount >= 4 ? (size_t)wxlua_getintegertype(L, 4) : 0);
119     // const wxString& replacement
120     wxString replacement = wxlua_getwxStringtype(L, 3);
121     // wxString* text
122     wxString text = wxlua_getwxStringtype(L, 2);
123     // get this
124     wxRegEx *self = (wxRegEx *)wxluaT_getuserdatatype(L, 1, wxluatype_wxRegEx);
125     // call Replace
126     int returns = self->Replace(&text, replacement, maxMatches);
127     // push the result number
128     lua_pushinteger(L, returns);
129     // push the result text
130     wxlua_pushwxString(L, text);
131     // return the number of parameters
132     return 2;
133 }
134 %end
135 
136 %override wxLua_wxRegEx_ReplaceAll
137 // int ReplaceAll(wxString* text, const wxString& replacement) const
138 static int LUACALL wxLua_wxRegEx_ReplaceAll(lua_State *L)
139 {
140     // const wxString& replacement
141     wxString replacement = wxlua_getwxStringtype(L, 3);
142     // wxString* text
143     wxString text = wxlua_getwxStringtype(L, 2);
144     // get this
145     wxRegEx *self = (wxRegEx *)wxluaT_getuserdatatype(L, 1, wxluatype_wxRegEx);
146     // call ReplaceAll
147     int returns = self->ReplaceAll(&text, replacement);
148     // push the result number
149     lua_pushinteger(L, returns);
150     // push the result text
151     wxlua_pushwxString(L, text);
152     // return the number of parameters
153     return 2;
154 }
155 %end
156 
157 %override wxLua_wxRegEx_ReplaceFirst
158 // int ReplaceFirst(wxString* text, const wxString& replacement) const
159 static int LUACALL wxLua_wxRegEx_ReplaceFirst(lua_State *L)
160 {
161     // const wxString& replacement
162     wxString replacement = wxlua_getwxStringtype(L, 3);
163     // wxString* text
164     wxString text = wxlua_getwxStringtype(L, 2);
165     // get this
166     wxRegEx *self = (wxRegEx *)wxluaT_getuserdatatype(L, 1, wxluatype_wxRegEx);
167     // call ReplaceFirst
168     int returns = self->ReplaceFirst(&text, replacement);
169     // push the result number
170     lua_pushinteger(L, returns);
171     // push the result text
172     wxlua_pushwxString(L, text);
173     // return the number of parameters
174     return 2;
175 }
176 %end
177 
178 %override wxLua_wxEvtHandler_CallAfter
179 class wxEvtHandlerLuaCallback : public wxEvtHandler
180 {
181 public:
Callback(lua_State * L,int funcref)182     void Callback(lua_State *L, int funcref) {
183         int old_top = lua_gettop(L);
184         lua_rawgeti(L, LUA_REGISTRYINDEX, funcref);
185         luaL_unref(L, LUA_REGISTRYINDEX, funcref); // remove ref to function
186         int res = lua_pcall(L, 0, 0, 0);
187         if (res > 0) lua_error(L);
188         lua_settop(L, old_top);
189     }
190 };
191 
wxLua_wxEvtHandler_CallAfter(lua_State * L)192 static int LUACALL wxLua_wxEvtHandler_CallAfter(lua_State *L)
193 {
194     if (!lua_isfunction(L, 2))
195         wxlua_argerror(L, 2, wxT("a Lua function"));
196 
197     lua_pushvalue(L, 2); // push function to top of stack
198     int funcref = luaL_ref(L, LUA_REGISTRYINDEX); // ref function and pop it from stack
199 
200     wxEvtHandler *self = (wxEvtHandler *)wxluaT_getuserdatatype(L, 1, wxluatype_wxEvtHandler);
201     self->CallAfter(&wxEvtHandlerLuaCallback::Callback, L, funcref);
202 
203     return 0;
204 }
205 %end
206 
207 %override wxLua_wxEvtHandler_Connect
208 // void Connect(int id, int lastId, wxEventType eventType, LuaFunction func)
209 
210 #include "wxlua/wxlcallb.h"
211 // Connect an event to a handler. This Lua 'C' function supports
212 // function calls with either three or four parameters. These parameters
213 // are:         The class (which must be derived from wxEvtHandler),
214 //              The event type
215 // (Optional)   The ID of the object the event is for
216 //              A Lua function to call to handle the event.
217 //              The Lua function gets called with a single parameter
218 //              which is a reference to the event object
219 //              associated with the event.
220 static int LUACALL wxLua_wxEvtHandler_Connect(lua_State *L)
221 {
222     wxCHECK_MSG(wxluatype_wxEvtHandler != -1, 0, wxT("wxEvtHandler is not wrapped by wxLua"));
223     wxLuaState wxlState(L);
224     wxCHECK_MSG(wxlState.Ok(), 0, wxT("Invalid wxLuaState"));
225 
226     wxWindowID  winId     = wxID_ANY;
227     wxWindowID  lastId    = wxID_ANY;
228     wxEventType eventType = wxEVT_NULL;
229 
230     int nParams = lua_gettop(L);
231 
232     wxEvtHandler *evtHandler = (wxEvtHandler *)wxluaT_getuserdatatype(L, 1, wxluatype_wxEvtHandler);
233 
234     int func_idx = 0;
235     int evttype_idx = 0;
236 
237     switch (nParams)
238     {
239         case 5:
240         {
241             //void Connect(int winid, int lastId, int eventType, wxObjectEventFunction func, wxObject *userData = (wxObject *) NULL, wxEvtHandler *eventSink = (wxEvtHandler *) NULL);
242             func_idx = 5;
243             evttype_idx = 4;
244 
245             if (wxlua_isintegertype(L, 3))
246                 lastId = (wxWindowID)lua_tonumber(L, 3);
247             else
248             {
249                 wxlua_argerror(L, 3, wxT("an 'integer wxWindowID'"));
250                 return 0;
251             }
252 
253             if (wxlua_isintegertype(L, 2))
254                 winId = (wxWindowID)lua_tonumber(L, 2);
255             else
256             {
257                 wxlua_argerror(L, 2, wxT("an 'integer wxWindowID'"));
258                 return 0;
259             }
260 
261             break;
262         }
263         case 4:
264         {
265             //void Connect(int winid, int eventType, wxObjectEventFunction func, wxObject *userData = (wxObject *) NULL, wxEvtHandler *eventSink = (wxEvtHandler *) NULL)
266             func_idx = 4;
267             evttype_idx = 3;
268 
269             if (wxlua_isintegertype(L, 2))
270                 winId  = (wxWindowID)lua_tonumber(L, 2);
271             else
272             {
273                 wxlua_argerror(L, 2, wxT("an 'integer wxWindowID'"));
274                 return 0;
275             }
276 
277             break;
278         }
279         case 3:
280         {
281             //void Connect(int eventType, wxObjectEventFunction func, wxObject *userData = (wxObject *) NULL, wxEvtHandler *eventSink = (wxEvtHandler *) NULL)
282             func_idx = 3;
283             evttype_idx = 2;
284             break;
285         }
286         default:
287         {
288             wxlua_argerrormsg(L, wxT("Incorrect number of arguments to wxEventHandler::Connect()."));
289             return 0;
290         }
291     }
292 
293     if (!lua_isfunction(L, func_idx))
294     {
295         wxlua_argerror(L, func_idx, wxT("a 'Lua function'"));
296         return 0;
297     }
298 
299     if (wxlua_isintegertype(L, evttype_idx))
300         eventType = (wxEventType)lua_tonumber(L, evttype_idx);
301     else
302     {
303         wxlua_argerror(L, evttype_idx, wxT("an 'integer wxEventType'"));
304         return 0;
305     }
306 
307     // Create and connect the callback
308     wxLuaEventCallback* pCallback = new wxLuaEventCallback;
309     wxString errMsg(pCallback->Connect(wxlState, func_idx, winId, lastId, eventType, evtHandler));
310     if (!errMsg.IsEmpty())
311     {
312         delete pCallback;
313         wxlua_error(L, errMsg.c_str());
314     }
315 
316     return 0;
317 }
318 %end
319 
320 %override wxLua_wxEvtHandler_Disconnect
321 // void Disconnect(int id, int lastId, wxEventType eventType)
322 
323 #include "wxlua/wxlcallb.h"
324 static int LUACALL wxLua_wxEvtHandler_Disconnect(lua_State *L)
325 {
326     wxCHECK_MSG(wxluatype_wxEvtHandler != -1, 0, wxT("wxEvtHandler is not wrapped by wxLua"));
327     wxLuaState wxlState(L);
328     wxCHECK_MSG(wxlState.Ok(), 0, wxT("Invalid wxLuaState"));
329 
330     wxWindowID  winId     = wxID_ANY;
331     wxWindowID  lastId    = wxID_ANY;
332     wxEventType eventType = wxEVT_NULL;
333 
334     int nParams = lua_gettop(L);
335 
336     wxEvtHandler *evtHandler = (wxEvtHandler *)wxluaT_getuserdatatype(L, 1, wxluatype_wxEvtHandler);
337 
338     int evttype_idx = 0;
339 
340     switch (nParams)
341     {
342         case 4:
343         {
344             //bool Disconnect(int winid, int lastId, wxEventType eventType, wxObjectEventFunction func = NULL, wxObject *userData = (wxObject *) NULL, wxEvtHandler *eventSink = (wxEvtHandler *) NULL);
345             evttype_idx = 4;
346 
347             if (wxlua_isintegertype(L, 3))
348                 lastId = (wxWindowID)lua_tonumber(L, 3);
349             else
350             {
351                 wxlua_argerror(L, 3, wxT("an 'integer wxWindowID'"));
352                 return 0;
353             }
354 
355             if (wxlua_isintegertype(L, 2))
356                 winId = (wxWindowID)lua_tonumber(L, 2);
357             else
358             {
359                 wxlua_argerror(L, 2, wxT("an 'integer wxWindowID'"));
360                 return 0;
361             }
362 
363             break;
364         }
365         case 3:
366         {
367             //bool Disconnect(int winid = wxID_ANY, wxEventType eventType = wxEVT_NULL, wxObjectEventFunction func = NULL, wxObject *userData = (wxObject *) NULL, wxEvtHandler *eventSink = (wxEvtHandler *) NULL)
368             evttype_idx = 3;
369 
370             if (wxlua_isintegertype(L, 2))
371                 winId  = (wxWindowID)lua_tonumber(L, 2);
372             else
373             {
374                 wxlua_argerror(L, 1, wxT("an 'integer wxWindowID'"));
375                 return 0;
376             }
377 
378             break;
379         }
380         case 2:
381         {
382             //bool Disconnect(wxEventType eventType, wxObjectEventFunction func, wxObject *userData = (wxObject *) NULL, wxEvtHandler *eventSink = (wxEvtHandler *) NULL)
383             evttype_idx = 2;
384 
385             break;
386         }
387         default:
388         {
389             wxlua_argerrormsg(L, wxT("Incorrect number of arguments to wxEventHandler::Disconnect()."));
390             return 0;
391         }
392     }
393 
394     if (wxlua_isintegertype(L, evttype_idx))
395         eventType = (wxEventType)lua_tonumber(L, evttype_idx);
396     else
397     {
398         wxlua_argerror(L, evttype_idx, wxT("an 'integer wxEventType'"));
399         return 0;
400     }
401 
402     // Try to disconnect from the callback, it will delete the wxLuaEventCallback.
403     bool returns = evtHandler->Disconnect(winId, lastId, eventType, (wxObjectEventFunction)&wxLuaEventCallback::OnAllEvents);
404 
405     lua_pushboolean(L, returns);
406     return 1;
407 }
408 %end
409 
410 // ----------------------------------------------------------------------------
411 // Overrides for wxbase_config.i
412 // ----------------------------------------------------------------------------
413 
414 %override wxLua_wxConfigBase_delete
415 // void delete()
416 static int LUACALL wxLua_wxConfigBase_delete(lua_State *L)
417 {
418     // get this
419     wxConfigBase *self = (wxConfigBase *)wxluaT_getuserdatatype(L, 1, wxluatype_wxConfigBase);
420 
421     if (wxConfigBase::Get(false) == self) // clear us from the wxConfigBase
422         wxConfigBase::Set(NULL);
423 
424     // we may not be tracked, but delete us anyway
425     if (!wxluaO_deletegcobject(L, 1, WXLUA_DELETE_OBJECT_ALL))
426         delete self;
427 
428     // return the number of parameters
429     return 0;
430 }
431 %end
432 
433 %override wxLua_wxConfigBase_Read
434 // bool Read(const wxString& key, wxString* str, const wxString& defaultVal = wxEmptyString) const
435 static int LUACALL wxLua_wxConfigBase_Read(lua_State *L)
436 {
437     wxString returns;
438     // get number of arguments
439     int argCount = lua_gettop(L);
440     // wxString defaultVal
441     wxString defaultVal = (argCount >= 3 ? wxlua_getwxStringtype(L, 3) : wxString(wxEmptyString));
442     // const wxString& key
443     wxString key = wxlua_getwxStringtype(L, 2);
444     // get this
445     wxConfigBase *self = (wxConfigBase *)wxluaT_getuserdatatype(L, 1, wxluatype_wxConfigBase);
446     // call Read
447     bool ret = self->Read(key, &returns, defaultVal);
448     // push the result bool
449     lua_pushboolean(L, ret);
450     // push the result string
451     wxlua_pushwxString(L, returns);
452     // return the number of parameters
453     return 2;
454 }
455 %end
456 
457 %override wxLua_wxConfigBase_ReadInt
458 // %rename ReadInt bool Read(const wxString&  key, long* l, long defaultVal = 0) const
459 static int LUACALL wxLua_wxConfigBase_ReadInt(lua_State *L)
460 {
461     long returns = 0;
462     // get number of arguments
463     int argCount = lua_gettop(L);
464     // double defaultVal = 0
465     long defaultVal = (argCount >= 3 ? (long)wxlua_getnumbertype(L, 3) : 0);
466     // const wxString& key
467     wxString key = wxlua_getwxStringtype(L, 2);
468     // get this
469     wxConfigBase *self = (wxConfigBase *)wxluaT_getuserdatatype(L, 1, wxluatype_wxConfigBase);
470     // call Read
471     bool ret = self->Read(key, &returns, defaultVal);
472     // push the result bool
473     lua_pushboolean(L, ret);
474     // push the result number
475     lua_pushinteger(L, returns);
476     // return the number of parameters
477     return 2;
478 }
479 %end
480 
481 %override wxLua_wxConfigBase_ReadFloat
482 // %rename ReadFloat bool Read(const wxString&  key, double* d, double defaultVal = 0) const
483 static int LUACALL wxLua_wxConfigBase_ReadFloat(lua_State *L)
484 {
485     double returns = 0;
486     // get number of arguments
487     int argCount = lua_gettop(L);
488     // double defaultVal = 0
489     double defaultVal = (argCount >= 3 ? (double)wxlua_getnumbertype(L, 3) : 0);
490     // const wxString& key
491     wxString key = wxlua_getwxStringtype(L, 2);
492     // get this
493     wxConfigBase *self = (wxConfigBase *)wxluaT_getuserdatatype(L, 1, wxluatype_wxConfigBase);
494     // call Read
495     bool ret = self->Read(key, &returns, defaultVal);
496     // push the result bool
497     lua_pushboolean(L, ret);
498     // push the result number
499     lua_pushinteger(L, returns);
500     // return the number of parameters
501     return 2;
502 }
503 %end
504 
505 %override wxLua_wxConfigBase_GetFirstGroup
506 // bool GetFirstGroup(wxString& str, long& index) const
507 static int LUACALL wxLua_wxConfigBase_GetFirstGroup(lua_State *L)
508 {
509     // get number of arguments
510     int argCount = lua_gettop(L);
511     // these are optional and are not used anyway
512     long     index = (argCount >= 3 ? (long)wxlua_getintegertype(L, 3) : 0);
513     wxString str   = (argCount >= 2 ? wxlua_getwxStringtype(L, 2) : wxString(wxEmptyString));
514     // get this
515     wxConfig *self = (wxConfig *)wxluaT_getuserdatatype(L, 1, wxluatype_wxConfigBase);
516     // call GetFirstGroup
517     bool returns = self->GetFirstGroup(str, index);
518     // push the result number
519     lua_pushboolean(L, returns);
520     // push the result string
521     wxlua_pushwxString(L, str);
522     // push the next index
523     lua_pushinteger(L, index);
524     // return the number of parameters
525     return 3;
526 }
527 %end
528 
529 %override wxLua_wxConfigBase_GetFirstEntry
530 // bool GetFirstEntry(wxString& str, long& index) const
531 static int LUACALL wxLua_wxConfigBase_GetFirstEntry(lua_State *L)
532 {
533     // get number of arguments
534     int argCount = lua_gettop(L);
535     // these are optional and are not used anyway
536     long     index = (argCount >= 3 ? (long)wxlua_getintegertype(L, 3) : 0);
537     wxString str   = (argCount >= 2 ? wxlua_getwxStringtype(L, 2) : wxString(wxEmptyString));
538     // get this
539     wxConfig *self = (wxConfig *)wxluaT_getuserdatatype(L, 1, wxluatype_wxConfigBase);
540     // call GetFirstEntry
541     bool returns = self->GetFirstEntry(str, index);
542     // push the result number
543     lua_pushboolean(L, returns);
544     // push the next string
545     wxlua_pushwxString(L, str);
546     // push the next index
547     lua_pushinteger(L, index);
548     // return the number of parameters
549     return 3;
550 }
551 %end
552 
553 %override wxLua_wxConfigBase_GetNextGroup
554 // bool GetNextGroup(wxString& str, long& index) const
555 static int LUACALL wxLua_wxConfigBase_GetNextGroup(lua_State *L)
556 {
557     // only the number is needed
558     long     index = (long)wxlua_getintegertype(L, 2);
559     wxString str;
560     // get this
561     wxConfig *self = (wxConfig *)wxluaT_getuserdatatype(L, 1, wxluatype_wxConfigBase);
562     // call GetNextGroup
563     bool returns = self->GetNextGroup(str, index);
564     // push the result number
565     lua_pushboolean(L, returns);
566     // push the next result string
567     wxlua_pushwxString(L, str);
568     // push the next index
569     lua_pushinteger(L, index);
570     // return the number of parameters
571     return 3;
572 }
573 %end
574 
575 %override wxLua_wxConfigBase_GetNextEntry
576 // bool GetNextEntry(wxString& str, long& index) const
577 static int LUACALL wxLua_wxConfigBase_GetNextEntry(lua_State *L)
578 {
579     // only the number is needed
580     long     index = (long)wxlua_getintegertype(L, 2);
581     wxString str;
582     // get this
583     wxConfig *self = (wxConfig *)wxluaT_getuserdatatype(L, 1, wxluatype_wxConfigBase);
584     // call GetNextEntry
585     bool returns = self->GetNextEntry(str, index);
586     // push the result number
587     lua_pushboolean(L, returns);
588     // push the result string
589     wxlua_pushwxString(L, str);
590     // push the next index
591     lua_pushinteger(L, index);
592     // return the number of parameters
593     return 3;
594 }
595 %end
596 
597 // ----------------------------------------------------------------------------
598 // Overrides for wxbase_data.i
599 // ----------------------------------------------------------------------------
600 
601 %override wxLua_wxString_constructor
602 //     wxString(const wxString& str = "")
603 static int LUACALL wxLua_wxString_constructor(lua_State *L)
604 {
605     // get number of arguments
606     int argCount = lua_gettop(L);
607     // const wxString str = ""
608     const wxString str = (argCount >= 1 ? wxlua_getwxStringtype(L, 1) : wxString(wxEmptyString));
609     // call constructor
610     wxString* returns = new wxString(str);
611     // add to tracked memory list
612     wxluaO_addgcobject(L, returns, wxluatype_wxString);
613     // push the constructed class pointer
614     wxluaT_pushuserdatatype(L, returns, wxluatype_wxString);
615 
616     return 1;
617 }
618 %end
619 
620 %override wxLua_wxClassInfo_constructor
621 // wxClassInfo(const wxString &name)
622 static int LUACALL wxLua_wxClassInfo_constructor(lua_State *L)
623 {
624     // const wxString &name
625     wxString name = wxlua_getwxStringtype(L, 1);
626     // call constructor
627 #if wxCHECK_VERSION(2, 9, 0)
628     wxClassInfo *returns = wxClassInfo::FindClass(name);
629 #else
630     wxClassInfo *returns = wxClassInfo::FindClass(name.wx_str());
631 #endif
632     // push the constructed class pointer
633     wxluaT_pushuserdatatype(L, returns, wxluatype_wxClassInfo);
634     // return the number of parameters
635     return 1;
636 }
637 %end
638 
639 %override wxLua_wxObjectRefData_delete_function
640 
641 #if wxCHECK_VERSION(2,9,0)
642 void wxLua_wxObjectRefData_delete_function(void** p)
643 {
644     wxObjectRefData* o = (wxObjectRefData*)(*p);
645     o->DecRef();
646 }
647 #else
648 void wxLua_wxObjectRefData_delete_function(void** p)
649 {
650     wxObjectRefData* o = (wxObjectRefData*)(*p);
651     delete o;
652 }
653 #endif
654 
655 %end
656 
657 %override wxLua_wxObject_DynamicCast
658 // void *DynamicCast(const char *class)
659 
660 // Attempt to cast an object reference (the first parameter) to another type.
661 // The type requested is specified by the second parameter. Presumably the
662 // type requested will be derived from the supplied object, otherwise
663 // bad things will happen.
664 static int LUACALL wxLua_wxObject_DynamicCast(lua_State *L)
665 {
666     int         iResult   = 0;
667     const char *className = lua_tostring(L, 2);
668     if (className != NULL)
669     {
670         // The userdata object must be derived from a wxObject for this
671         // function be be called.
672         wxObject *pObject = (wxObject *)wxlua_touserdata(L, 1, false);
673         //wxObject *pObject = (wxObject *)wxluaT_getuserdatatype(L, 1, wxluatype_wxObject);
674 
675         const wxLuaBindClass *wxlClass = wxluaT_getclass(L, className);
676         if (pObject && wxlClass && wxlClass->classInfo)
677         {
678             if (pObject->IsKindOf(wxlClass->classInfo))
679             {
680                 if (*wxlClass->wxluatype != wxluaT_type(L, 1))
681                     wxluaT_pushuserdatatype(L, pObject, *wxlClass->wxluatype);
682                 else
683                     lua_pushvalue(L, 1); // return same userdata
684 
685                 iResult = 1;
686             }
687             else
688                 wxlua_argerrormsg(L, wxString::Format(wxT("wxLua: wxObject::DynamicCast() Unable to cast a '%s' to a '%s' with wxClassInfo '%s'."),
689                                      pObject->GetClassInfo()->GetClassName(),
690                                      lua2wx(className).c_str(),
691                                      wxString(wxlClass ? wxlClass->classInfo->GetClassName() : wxT("Unknown")).c_str()));
692         }
693 
694         if (iResult == 0)
695             wxlua_argerrormsg(L, wxString::Format(wxT("wxLua: wxObject::DynamicCast() Cannot cast a wxLua type '%s' with wxClassInfo '%s' to a '%s'."),
696                                  wxluaT_gettypename(L, 1).c_str(),
697                                  wxString(pObject ? pObject->GetClassInfo()->GetClassName() : wxT("Unknown")).c_str(),
698                                  lua2wx(className).c_str()));
699     }
700     else
701         wxlua_argerror(L, 2, wxT("a 'string name of the class'"));
702 
703     return iResult;
704 }
705 %end
706 
707 %override wxLua_wxArrayInt_ToLuaTable
708 // int ToLuaTable() const
709 static int LUACALL wxLua_wxArrayInt_ToLuaTable(lua_State *L)
710 {
711     wxArrayInt * self = (wxArrayInt *)wxluaT_getuserdatatype(L, 1, wxluatype_wxArrayInt);
712     wxlua_pushwxArrayInttable(L, *self);
713     return 1;
714 }
715 %end
716 
717 %override wxLua_wxArrayDouble_ToLuaTable
718 // int ToLuaTable() const
719 static int LUACALL wxLua_wxArrayDouble_ToLuaTable(lua_State *L)
720 {
721     wxArrayDouble * self = (wxArrayDouble *)wxluaT_getuserdatatype(L, 1, wxluatype_wxArrayDouble);
722     wxlua_pushwxArrayDoubletable(L, *self);
723     return 1;
724 }
725 %end
726 
727 %override wxLua_wxArrayString_ToLuaTable
728 // int ToLuaTable() const
729 static int LUACALL wxLua_wxArrayString_ToLuaTable(lua_State *L)
730 {
731     wxArrayString * self = (wxArrayString *)wxluaT_getuserdatatype(L, 1, wxluatype_wxArrayString);
732     wxlua_pushwxArrayStringtable(L, *self);
733     return 1;
734 }
735 %end
736 
737 %override wxLua_wxMemoryBuffer_GetByte
738 //     unsigned char GetByte(int index, size_t length = 1);
739 static int LUACALL wxLua_wxMemoryBuffer_GetByte(lua_State *L)
740 {
741     // int index
742     int index = (int)wxlua_getnumbertype(L, 2);
743     // get this
744     wxMemoryBuffer * self = (wxMemoryBuffer *)wxluaT_getuserdatatype(L, 1, wxluatype_wxMemoryBuffer);
745     if (index < 0 || (unsigned)index >= self->GetDataLen())
746         return 0;
747     // int length (optional)
748     int length = 1;
749     if (lua_gettop(L) >= 3)
750         length = (size_t)wxlua_getnumbertype(L, 3);
751     if (length <= 0)
752         return 0;
753     if ((unsigned)(index + length) > self->GetDataLen())
754         length = self->GetDataLen() - index;
755     int count = 0;
756     while (count < length) {
757         unsigned char returns = ((unsigned char *)(self->GetData()))[index + count];
758         lua_pushinteger(L, returns);
759         count++;
760     }
761     return length;
762 }
763 %end
764 
765 %override wxLua_wxMemoryBuffer_SetByte
766 //     void SetByte(int index, unsigned char data);
767 static int LUACALL wxLua_wxMemoryBuffer_SetByte(lua_State *L)
768 {
769     // int index
770     int index = (int)wxlua_getnumbertype(L, 2);
771     wxASSERT_MSG(index >= 0, "index out of range");
772     // get this
773     wxMemoryBuffer * self = (wxMemoryBuffer *)wxluaT_getuserdatatype(L, 1, wxluatype_wxMemoryBuffer);
774     // more data? (optional)
775     int length = lua_gettop(L) - 2;
776     if (length <= 0)
777         return 0;  //  Do nothing
778     // get data pointer
779     unsigned char *dptr = (unsigned char *)self->GetWriteBuf(index + length);
780     wxASSERT_MSG(dptr != NULL, "cannot reallocate buffer");
781     int count = 0;
782     while (count < length) {
783         ((unsigned char *)(self->GetData()))[index + count] = (unsigned char)wxlua_getnumbertype(L, 3 + count);
784         count++;
785     }
786     if (self->GetDataLen() < (unsigned)(index + length))
787         self->SetDataLen(index + length);
788     return 0;
789 }
790 %end
791 
792 %override wxLua_wxMemoryBuffer_Fill
793 //     void Fill(unsigned char data, int start_index, size_t length);
794 static int LUACALL wxLua_wxMemoryBuffer_Fill(lua_State *L)
795 {
796     // size_t length
797     size_t length = (size_t)wxlua_getnumbertype(L, 4);
798     // int start_index
799     int start_index = (int)wxlua_getnumbertype(L, 3);
800     // unsigned char data
801     int data = (unsigned char)wxlua_getnumbertype(L, 2);
802     wxASSERT_MSG(start_index >= 0, "index out of range");
803     // get this
804     wxMemoryBuffer * self = (wxMemoryBuffer *)wxluaT_getuserdatatype(L, 1, wxluatype_wxMemoryBuffer);
805     if (length <= 0)
806         return 0;  //  Do nothing
807     // get data pointer
808     unsigned char *dptr = (unsigned char *)self->GetWriteBuf(start_index + length);
809     wxASSERT_MSG(dptr != NULL, "cannot reallocate buffer");
810     memset(dptr + start_index, data, length);
811     if (self->GetDataLen() < start_index + length)
812         self->SetDataLen(start_index + length);
813     return 0;
814 }
815 %end
816 
817 // ----------------------------------------------------------------------------
818 // Overrides for wxbase_datetime.i
819 // ----------------------------------------------------------------------------
820 
821 %override wxLua_wxDateTime_ParseRfc822Date
822 //     %wxchkver_2_9 bool ParseRfc822Date(const wxString& date)
823 static int LUACALL wxLua_wxDateTime_ParseRfc822Date(lua_State *L)
824 {
825     // const wxString date
826     const wxString date = wxlua_getwxStringtype(L, 2);
827     wxString::const_iterator it(date.begin());
828     // get this
829     wxDateTime * self = (wxDateTime *)wxluaT_getuserdatatype(L, 1, wxluatype_wxDateTime);
830     // call ParseRfc822Date
831     bool returns = (self->ParseRfc822Date(date, &it));
832     // push the result flag
833     lua_pushboolean(L, returns);
834 
835     if (!returns && (it != date.end()))
836     {
837         wxlua_pushwxString(L, wxString(it, date.end()));
838         return 2;
839     }
840 
841     return 1;
842 }
843 %end
844 
845 %override wxLua_wxDateTime_ParseFormat2
846 //     %wxchkver_2_9 bool ParseFormat(const wxString& date)
847 static int LUACALL wxLua_wxDateTime_ParseFormat2(lua_State *L)
848 {
849     // const wxString date
850     const wxString date = wxlua_getwxStringtype(L, 2);
851     wxString::const_iterator it(date.begin());
852     // get this
853     wxDateTime * self = (wxDateTime *)wxluaT_getuserdatatype(L, 1, wxluatype_wxDateTime);
854     // call ParseFormat
855     bool returns = (self->ParseFormat(date, &it));
856     // push the result flag
857     lua_pushboolean(L, returns);
858 
859     if (!returns && (it != date.end()))
860     {
861         wxlua_pushwxString(L, wxString(it, date.end()));
862         return 2;
863     }
864 
865 
866     return 1;
867 }
868 %end
869 
870 %override wxLua_wxDateTime_ParseFormat1
871 //     %wxchkver_2_9 bool ParseFormat(const wxString& date, wxString format)
872 static int LUACALL wxLua_wxDateTime_ParseFormat1(lua_State *L)
873 {
874     // wxString format
875     wxString format = wxlua_getwxStringtype(L, 3);
876     // const wxString date
877     const wxString date = wxlua_getwxStringtype(L, 2);
878     wxString::const_iterator it(date.begin());
879     // get this
880     wxDateTime * self = (wxDateTime *)wxluaT_getuserdatatype(L, 1, wxluatype_wxDateTime);
881     // call ParseFormat
882     bool returns = (self->ParseFormat(date, format, &it));
883     // push the result flag
884     lua_pushboolean(L, returns);
885 
886     if (!returns && (it != date.end()))
887     {
888         wxlua_pushwxString(L, wxString(it, date.end()));
889         return 2;
890     }
891 
892     return 1;
893 }
894 %end
895 
896 %override wxLua_wxDateTime_ParseFormat
897 //     %wxchkver_2_9 bool ParseFormat(const wxString& date, wxString format, const wxDateTime& dateDef)
898 static int LUACALL wxLua_wxDateTime_ParseFormat(lua_State *L)
899 {
900     // const wxDateTime dateDef
901     const wxDateTime * dateDef = (const wxDateTime *)wxluaT_getuserdatatype(L, 4, wxluatype_wxDateTime);
902     // wxString format
903     wxString format = wxlua_getwxStringtype(L, 3);
904     // const wxString date
905     const wxString date = wxlua_getwxStringtype(L, 2);
906     wxString::const_iterator it(date.begin());
907     // get this
908     wxDateTime * self = (wxDateTime *)wxluaT_getuserdatatype(L, 1, wxluatype_wxDateTime);
909     // call ParseFormat
910     bool returns = (self->ParseFormat(date, format, *dateDef, &it));
911     // push the result flag
912     lua_pushboolean(L, returns);
913 
914     if (!returns && (it != date.end()))
915     {
916         wxlua_pushwxString(L, wxString(it, date.end()));
917         return 2;
918     }
919 
920     return 1;
921 }
922 %end
923 
924 %override wxLua_wxDateTime_ParseDateTime
925 //     %wxchkver_2_9 bool ParseDateTime(const wxString& datetime)
926 static int LUACALL wxLua_wxDateTime_ParseDateTime(lua_State *L)
927 {
928     // const wxString datetime
929     const wxString datetime = wxlua_getwxStringtype(L, 2);
930     wxString::const_iterator it(datetime.begin());
931     // get this
932     wxDateTime * self = (wxDateTime *)wxluaT_getuserdatatype(L, 1, wxluatype_wxDateTime);
933     // call ParseDateTime
934     bool returns = (self->ParseDateTime(datetime, &it));
935     // push the result flag
936     lua_pushboolean(L, returns);
937 
938     if (!returns && (it != datetime.end()))
939     {
940         wxlua_pushwxString(L, wxString(it, datetime.end()));
941         return 2;
942     }
943 
944     return 1;
945 }
946 %end
947 
948 %override wxLua_wxDateTime_ParseDate
949 //     %wxchkver_2_9 bool ParseDate(const wxString& date)
950 static int LUACALL wxLua_wxDateTime_ParseDate(lua_State *L)
951 {
952     // const wxString date
953     const wxString date = wxlua_getwxStringtype(L, 2);
954     wxString::const_iterator it(date.begin());
955     // get this
956     wxDateTime * self = (wxDateTime *)wxluaT_getuserdatatype(L, 1, wxluatype_wxDateTime);
957     // call ParseDate
958     bool returns = (self->ParseDate(date, &it));
959     // push the result flag
960     lua_pushboolean(L, returns);
961 
962     if (!returns && (it != date.end()))
963     {
964         wxlua_pushwxString(L, wxString(it, date.end()));
965         return 2;
966     }
967 
968     return 1;
969 }
970 %end
971 
972 %override wxLua_wxDateTime_ParseTime
973 //     %wxchkver_2_9 bool ParseTime(const wxString& time)
974 static int LUACALL wxLua_wxDateTime_ParseTime(lua_State *L)
975 {
976     // const wxString time
977     const wxString time = wxlua_getwxStringtype(L, 2);
978     wxString::const_iterator it(time.begin());
979     // get this
980     wxDateTime * self = (wxDateTime *)wxluaT_getuserdatatype(L, 1, wxluatype_wxDateTime);
981     // call ParseTime
982     bool returns = (self->ParseTime(time, &it));
983     // push the result flag
984     lua_pushboolean(L, returns);
985 
986     if (!returns && (it != time.end()))
987     {
988     wxString s(it, time.end());
989         wxlua_pushwxString(L, s);
990         return 2;
991     }
992 
993     return 1;
994 }
995 %end
996 
997 // ----------------------------------------------------------------------------
998 // Overrides for wxbase_file.i
999 // ----------------------------------------------------------------------------
1000 
1001 %override wxLua_function_wxDos2UnixFilename
1002 // %function wxString wxDos2UnixFilename(const wxString& s)
1003 static int LUACALL wxLua_function_wxDos2UnixFilename(lua_State *L)
1004 {
1005     wxString str = lua2wx(lua_tostring(L, 1));
1006     if (!str.IsEmpty())
1007     {
1008         // call wxDos2UnixFilename
1009         wxDos2UnixFilename((wxChar*)str.GetData());
1010         // push the result string
1011         wxlua_pushwxString(L, str);
1012 
1013         return 1;
1014     }
1015     return 0;
1016 }
1017 %end
1018 
1019 %override wxLua_function_wxUnix2DosFilename
1020 // %function wxString wxUnix2DosFilename(const wxString& s)
1021 static int LUACALL wxLua_function_wxUnix2DosFilename(lua_State *L)
1022 {
1023     wxString str = lua2wx(lua_tostring(L, 1));
1024     if (!str.IsEmpty())
1025     {
1026         // call wxUnix2DosFilename
1027         wxUnix2DosFilename((wxChar*)str.GetData());
1028         // push the result string
1029         wxlua_pushwxString(L, str);
1030 
1031         return 1;
1032     }
1033     return 0;
1034 }
1035 %end
1036 
1037 %override wxLua_function_wxFileSize
1038 // %function long wxFileSize(const wxString& fileName)
1039 static int LUACALL wxLua_function_wxFileSize(lua_State *L)
1040 {
1041     wxString str = lua2wx(lua_tostring(L, 1));
1042     if (!str.IsEmpty())
1043     {
1044         wxStructStat statstr;
1045         wxStat(str, &statstr);
1046         // push the result string
1047         lua_pushinteger(L, (int)statstr.st_size);
1048 
1049         return 1;
1050     }
1051     return 0;
1052 }
1053 %end
1054 
1055 %override wxLua_wxFileName_GetDirs
1056 //     const wxArrayString& GetDirs() const
1057 static int LUACALL wxLua_wxFileName_GetDirs(lua_State *L)
1058 {
1059     // get this
1060     wxFileName * self = (wxFileName *)wxluaT_getuserdatatype(L, 1, wxluatype_wxFileName);
1061     // call GetDirs
1062     wxArrayString returns = self->GetDirs();
1063     // push the result datatype
1064     wxlua_pushwxArrayStringtable(L, returns);
1065 
1066     return 1;
1067 }
1068 %end
1069 
1070 %override wxLua_wxFileName_GetTimes
1071 // bool GetTimes(wxDateTime* dtAccess, wxDateTime* dtMod, wxDateTime* dtCreate) const
1072 static int LUACALL wxLua_wxFileName_GetTimes(lua_State *L)
1073 {
1074     wxDateTime *dtCreate = new wxDateTime();
1075     wxDateTime *dtMod = new wxDateTime();
1076     wxDateTime *dtAccess= new wxDateTime();
1077     // get this
1078     wxFileName *self = (wxFileName *)wxluaT_getuserdatatype(L, 1, wxluatype_wxFileName);
1079     // call GetTimes
1080     bool returns = self->GetTimes(dtAccess, dtMod, dtCreate);
1081     // push the result flag
1082     lua_pushboolean(L, returns);
1083     // add to tracked memory list
1084     wxluaO_addgcobject(L, (void*)dtAccess, wxluatype_wxDateTime);
1085     wxluaO_addgcobject(L, (void*)dtMod,    wxluatype_wxDateTime);
1086     wxluaO_addgcobject(L, (void*)dtCreate, wxluatype_wxDateTime);
1087     // push the constructed class pointers
1088     wxluaT_pushuserdatatype(L, dtAccess, wxluatype_wxDateTime);
1089     wxluaT_pushuserdatatype(L, dtMod,    wxluatype_wxDateTime);
1090     wxluaT_pushuserdatatype(L, dtCreate, wxluatype_wxDateTime);
1091     // return the number of parameters
1092     return 4;
1093 }
1094 %end
1095 
1096 %override wxLua_wxFileName_SplitPath
1097 // static void SplitPath(const wxString& fullpath, wxString* volume, wxString* path, wxString* name, wxString* ext, wxPathFormat format = wxPATH_NATIVE)
1098 static int LUACALL wxLua_wxFileName_SplitPath(lua_State *L)
1099 {
1100     // get number of arguments
1101     int argCount = lua_gettop(L);
1102     // wxPathFormat format = wxPATH_NATIVE
1103     wxPathFormat format = (argCount >= 2 ? (wxPathFormat)wxlua_getenumtype(L, 2) : wxPATH_NATIVE);
1104     wxString ext;
1105     wxString name;
1106     wxString path;
1107     // const wxString& fullpath
1108     wxString fullpath = wxlua_getwxStringtype(L, 1);
1109     // call SplitPath
1110     wxFileName::SplitPath(fullpath, &path, &name, &ext, format);
1111     // push the result strings
1112     wxlua_pushwxString(L, path);
1113     wxlua_pushwxString(L, name);
1114     wxlua_pushwxString(L, ext);
1115     // return the number of parameters
1116     return 3;
1117 }
1118 %end
1119 
1120 %override wxLua_wxFileName_SplitPathVolume
1121 // static void SplitPath(const wxString& fullpath, wxString* volume, wxString* path, wxString* name, wxString* ext, wxPathFormat format = wxPATH_NATIVE)
1122 static int LUACALL wxLua_wxFileName_SplitPathVolume(lua_State *L)
1123 {
1124     // get number of arguments
1125     int argCount = lua_gettop(L);
1126     // wxPathFormat format = wxPATH_NATIVE
1127     wxPathFormat format = (argCount >= 2 ? (wxPathFormat)wxlua_getenumtype(L, 2) : wxPATH_NATIVE);
1128     wxString ext;
1129     wxString name;
1130     wxString path;
1131     wxString volume;
1132     // const wxString& fullpath
1133     wxString fullpath = wxlua_getwxStringtype(L, 1);
1134     // call SplitPath
1135     wxFileName::SplitPath(fullpath, &volume, &path, &name, &ext, format);
1136     // push the result strings
1137     wxlua_pushwxString(L, volume);
1138     wxlua_pushwxString(L, path);
1139     wxlua_pushwxString(L, name);
1140     wxlua_pushwxString(L, ext);
1141     // return the number of parameters
1142     return 4;
1143 }
1144 %end
1145 
1146 %override wxLua_wxFileName_SplitVolume
1147 //     static void SplitVolume(const wxString& fullpath, wxString* volume, wxString* path, wxPathFormat format = wxPATH_NATIVE)
1148 static int LUACALL wxLua_wxFileName_SplitVolume(lua_State *L)
1149 {
1150     // get number of arguments
1151     int argCount = lua_gettop(L);
1152     // wxPathFormat format = wxPATH_NATIVE
1153     wxPathFormat format = (argCount >= 2 ? (wxPathFormat)wxlua_getenumtype(L, 2) : wxPATH_NATIVE);
1154     // const wxString fullpath
1155     const wxString fullpath = wxlua_getwxStringtype(L, 1);
1156     wxString volume;
1157     wxString path;
1158     // call SplitVolume
1159     wxFileName::SplitVolume(fullpath, &volume, &path, format);
1160     // push the result strings
1161     wxlua_pushwxString(L, volume);
1162     wxlua_pushwxString(L, path);
1163     return 2;
1164 }
1165 %end
1166 
1167 %override wxLua_wxDir_GetFirst
1168 // bool GetFirst(wxString * filename, const wxString& filespec = "", int flags = wxDIR_DEFAULT) const
1169 static int LUACALL wxLua_wxDir_GetFirst(lua_State *L)
1170 {
1171     // get number of arguments
1172     int argCount = lua_gettop(L);
1173     // int flags = wxDIR_DEFAULT
1174     int flags = (argCount >= 3 ? (int)wxlua_getintegertype(L, 3) : wxDIR_DEFAULT);
1175     // const wxString& filespec = ""
1176     wxString filespec = (argCount >= 2 ? wxlua_getwxStringtype(L, 2) : wxString(wxT("")));
1177     // wxString * filename
1178     wxString filename;
1179     // get this
1180     wxDir *self = (wxDir *)wxluaT_getuserdatatype(L, 1, wxluatype_wxDir);
1181     // call GetFirst
1182     bool returns = self->GetFirst(&filename, filespec, flags);
1183     lua_pushboolean(L, returns);
1184     // push the result number
1185     wxlua_pushwxString(L, filename);
1186     // return the number of parameters
1187     return 2;
1188 }
1189 %end
1190 
1191 %override wxLua_wxDir_GetNext
1192 // bool GetNext(wxString * filename) const
1193 static int LUACALL wxLua_wxDir_GetNext(lua_State *L)
1194 {
1195     // wxString * filename
1196     wxString filename;
1197     // get this
1198     wxDir *self = (wxDir *)wxluaT_getuserdatatype(L, 1, wxluatype_wxDir);
1199     // call GetNext
1200     bool returns = self->GetNext(&filename);
1201     lua_pushboolean(L, returns);
1202     // push the result number
1203     wxlua_pushwxString(L, filename);
1204     // return the number of parameters
1205     return 2;
1206 }
1207 %end
1208 
1209 %override wxLua_wxDir_GetAllFiles
1210 // static unsigned int GetAllFiles(const wxString& dirname, wxArrayString *files, const wxString& filespec = "", int flags = wxDIR_DEFAULT)
1211 static int LUACALL wxLua_wxDir_GetAllFiles(lua_State *L)
1212 {
1213     // get number of arguments
1214     int argCount = lua_gettop(L);
1215     // int flags = wxDIR_DEFAULT
1216     int flags = (argCount >= 3 ? (int)wxlua_getintegertype(L, 3) : wxDIR_DEFAULT);
1217     // const wxString& filespec = ""
1218     wxString filespec = (argCount >= 2 ? wxlua_getwxStringtype(L, 2) : wxString(wxT("")));
1219     // wxArrayString *files
1220     wxArrayString files;
1221     // const wxString& dirname
1222     wxString dirname = wxlua_getwxStringtype(L, 1);
1223     // call GetAllFiles
1224     unsigned int returns = wxDir::GetAllFiles(dirname, &files, filespec, flags);
1225     // push the result number
1226     lua_pushinteger(L, returns);
1227     wxlua_pushwxArrayStringtable(L, files);
1228     // return the number of parameters
1229     return 2;
1230 }
1231 %end
1232 
1233 %override wxLua_wxFile_Read
1234 // unsigned int Read(void * buffer,  unsigned int count)
1235 static int LUACALL wxLua_wxFile_Read(lua_State *L)
1236 {
1237     // unsigned int count
1238     unsigned int count = (unsigned int)wxlua_getintegertype(L, 2);
1239     // void * buffer
1240     void *buffer = malloc(count);
1241     if (buffer != NULL)
1242     {
1243         // get this
1244         wxFile *self = (wxFile *)wxluaT_getuserdatatype(L, 1, wxluatype_wxFile);
1245         // call Read
1246         unsigned int returns = self->Read(buffer, count);
1247         // push the result number
1248         lua_pushinteger(L, returns);
1249         lua_pushlstring(L, (const char *) buffer, returns);
1250         free(buffer);
1251         // return the number of parameters
1252         return 2;
1253     }
1254     return 0;
1255 }
1256 %end
1257 
1258 %override wxLua_wxFile_Write
1259 // unsigned int Write(const void * buffer, unsigned int nbytes)
1260 static int LUACALL wxLua_wxFile_Write(lua_State *L)
1261 {
1262     // get number of arguments
1263     int argCount = lua_gettop(L);
1264     // unsigned long nbytes
1265     unsigned long nbytes = (argCount >= 3 ? (unsigned long)wxlua_getintegertype(L, 3) : lua_strlen(L, 2));
1266     // const void * buffer
1267     const void *buffer = (const void *)lua_tostring(L, 2);
1268     // get this
1269     wxFile *self = (wxFile *)wxluaT_getuserdatatype(L, 1, wxluatype_wxFile);
1270     // call Write
1271     unsigned int returns = self->Write(buffer, nbytes);
1272     // push the result number
1273     lua_pushinteger(L, returns);
1274     // return the number of parameters
1275     return 1;
1276 }
1277 %end
1278 
1279 %override wxLua_wxFileType_GetDescription
1280 //     bool GetDescription(wxString *desc) const;
1281 static int LUACALL wxLua_wxFileType_GetDescription(lua_State *L)
1282 {
1283     // wxString desc
1284     wxString desc; // = wxlua_getwxStringtype(L, 2);
1285     // get this
1286     wxFileType * self = (wxFileType *)wxluaT_getuserdatatype(L, 1, wxluatype_wxFileType);
1287     // call GetDescription
1288     bool returns = (self->GetDescription(&desc));
1289     // push the result flag
1290     lua_pushboolean(L, returns);
1291     wxlua_pushwxString(L, desc);
1292 
1293     return 2;
1294 }
1295 %end
1296 
1297 %override wxLua_wxFileType_GetPrintCommand
1298 //     bool GetPrintCommand(wxString *printCmd, const wxFileType::MessageParameters& params) const;
1299 static int LUACALL wxLua_wxFileType_GetPrintCommand(lua_State *L)
1300 {
1301     // const wxFileType::MessageParameters params
1302     const wxFileType::MessageParameters * params = (const wxFileType::MessageParameters *)wxluaT_getuserdatatype(L, 3, wxluatype_wxFileType_MessageParameters);
1303     // wxString printCmd
1304     wxString printCmd; // = wxlua_getwxStringtype(L, 2);
1305     // get this
1306     wxFileType * self = (wxFileType *)wxluaT_getuserdatatype(L, 1, wxluatype_wxFileType);
1307     // call GetPrintCommand
1308     bool returns = (self->GetPrintCommand(&printCmd, *params));
1309     // push the result flag
1310     lua_pushboolean(L, returns);
1311     wxlua_pushwxString(L, printCmd);
1312 
1313     return 2;
1314 }
1315 %end
1316 
1317 %override wxLua_wxInputStream_Read
1318 // wxInputStream& Read(void *buffer, size_t size)
1319 static int LUACALL wxLua_wxInputStream_Read(lua_State *L)
1320 {
1321     // size_t size
1322     size_t size = (size_t)wxlua_getintegertype(L, 2);
1323     // void *buffer
1324     void *buffer = malloc(size);
1325     // get this
1326     wxInputStream *self = (wxInputStream *)wxluaT_getuserdatatype(L, 1, wxluatype_wxInputStream);
1327     if (buffer != NULL)
1328     {
1329         // call Read
1330         // wxInputStream *returns = & // we don't return wxInputStream
1331         self->Read(buffer, size);
1332         // only return the data that was read, they already have self
1333         //wxluaT_pushuserdatatype(L, returns, wxluatype_wxInputStream);
1334         lua_pushlstring(L, (const char *)buffer, size);
1335         free(buffer);
1336         return 1;
1337     }
1338     return 0;
1339 }
1340 %end
1341 
1342 %override wxLua_wxInputStream_UngetchString
1343 // size_t Ungetch(const char* buffer, size_t size)
1344 static int LUACALL wxLua_wxInputStream_UngetchString(lua_State *L)
1345 {
1346     // size_t size
1347     size_t size = (size_t)wxlua_getintegertype(L, 3);
1348     // const char* buffer
1349     const char *buffer = (const char *)lua_tostring(L, 2);
1350     // get this
1351     wxInputStream *self = (wxInputStream *)wxluaT_getuserdatatype(L, 1, wxluatype_wxInputStream);
1352     // call Ungetch
1353     size_t returns = self->Ungetch(buffer, size);
1354     // push the result number
1355     lua_pushinteger(L, returns);
1356     // return the number of parameters
1357     return 1;
1358 }
1359 %end
1360 
1361 %override wxLua_wxOutputStream_Write
1362 // wxOutputStream& Write(const void *buffer, size_t size)
1363 static int LUACALL wxLua_wxOutputStream_Write(lua_State *L)
1364 {
1365     // size_t size
1366     size_t size = (size_t)wxlua_getintegertype(L, 3);
1367     // const void *buffer
1368     const void *buffer = (void *)lua_tostring(L, 2);
1369     // get this
1370     wxOutputStream *self = (wxOutputStream *)wxluaT_getuserdatatype(L, 1, wxluatype_wxOutputStream);
1371     // call Write
1372     wxOutputStream *returns = &self->Write(buffer, size);
1373     // push the result datatype
1374     wxluaT_pushuserdatatype(L, returns, wxluatype_wxOutputStream);
1375     // return the number of parameters
1376     return 1;
1377 }
1378 %end
1379 
1380 
1381 %override wxLua_wxMemoryInputStream_constructor
1382 //     wxMemoryInputStream(const char *data, size_t length)
1383 static int LUACALL wxLua_wxMemoryInputStream_constructor(lua_State *L)
1384 {
1385     // size_t length
1386     size_t length = (size_t)wxlua_getnumbertype(L, 2);
1387     // const char data
1388     const char* data = (const char*)wxlua_getstringtype(L, 1);
1389     // call constructor
1390     wxMemoryInputStream* returns = new wxMemoryInputStream(data, length);
1391     // add to tracked memory list
1392     wxluaO_addgcobject(L, returns, wxluatype_wxMemoryInputStream);
1393     // push the constructed class pointer
1394     wxluaT_pushuserdatatype(L, returns, wxluatype_wxMemoryInputStream);
1395 
1396     return 1;
1397 }
1398 %end
1399 
1400 
1401 %override wxLua_wxFileSystem_FindFileInPath
1402 //     bool FindFileInPath(wxString *pStr, const wxChar *path, const wxChar *file);
1403 //     bool FindFileInPath(const wxString& path, const wxString& file);
1404 static int LUACALL wxLua_wxFileSystem_FindFileInPath(lua_State *L)
1405 {
1406     // const wxString file
1407     const wxString file_ = wxlua_getwxStringtype(L, 3);
1408     // const wxString path
1409     const wxString path = wxlua_getwxStringtype(L, 2);
1410     // get this
1411     wxFileSystem * self = (wxFileSystem *)wxluaT_getuserdatatype(L, 1, wxluatype_wxFileSystem);
1412     // call FindFileInPath
1413     wxString str;
1414     bool returns = (self->FindFileInPath(&str, path, file_));
1415     // push the result flag
1416     lua_pushboolean(L, returns);
1417     wxlua_pushwxString(L, str);
1418 
1419     return 2;
1420 }
1421 %end
1422