Ardour  9.0-pre0-582-g084a23a80d
Namespace.h
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 /*
3  https://github.com/vinniefalco/LuaBridge
4 
5  Copyright 2016, Robin Gareus <robin@gareus.org>
6  Copyright 2012, Vinnie Falco <vinnie.falco@gmail.com>
7  Copyright 2007, Nathan Reed
8 
9  License: The MIT License (http://www.opensource.org/licenses/mit-license.php)
10 
11  Permission is hereby granted, free of charge, to any person obtaining a copy
12  of this software and associated documentation files (the "Software"), to deal
13  in the Software without restriction, including without limitation the rights
14  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15  copies of the Software, and to permit persons to whom the Software is
16  furnished to do so, subject to the following conditions:
17 
18  The above copyright notice and this permission notice shall be included in all
19  copies or substantial portions of the Software.
20 
21  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27  SOFTWARE.
28 */
29 //==============================================================================
30 
31 #include <memory>
32 
33 #ifdef LUABINDINGDOC
34 #include <iostream>
35 #include <typeinfo>
36 #include <execinfo.h>
37 #include <type_traits>
38 #include <cxxabi.h>
39 #include <string>
40 #include <cstdlib>
41 
42 template <class T>
43 std::string type_name()
44 {
45  typedef typename std::remove_reference<T>::type TR;
46  std::unique_ptr<char, void(*)(void*)> own
47  (
48  abi::__cxa_demangle(typeid(TR).name(), nullptr,
49  nullptr, nullptr),
50  std::free
51  );
52  std::string r = own != nullptr ? own.get() : typeid(TR).name();
53  if (std::is_const<TR>::value)
54  r += " const";
55  if (std::is_volatile<TR>::value)
56  r += " volatile";
57  if (std::is_lvalue_reference<T>::value)
58  r += "&";
59  else if (std::is_rvalue_reference<T>::value)
60  r += "&&";
61  return r;
62 }
63 
64 //#define LUADOCOUT
65 
66 #ifdef LUADOCOUT // lua
67 #define KEYSTA "[\""
68 #define KEYEND "\"] = "
69 #else // JSON
70 #define KEYSTA "\""
71 #define KEYEND "\" : "
72 #endif
73 
74 #define CLASSDOC(TYPE, LUANAME, DECL, PARENTDECL) \
75  if (LuaBindingDoc::printBindings ()) { \
76  std::cout << "{ " << KEYSTA << "type" << KEYEND << " \"" << TYPE << "\",\n"; \
77  std::cout << " " << KEYSTA << "lua" << KEYEND << " \"" << LUANAME << "\",\n"; \
78  std::cout << " " << KEYSTA << "decl" << KEYEND << " \"" << DECL << "\",\n"; \
79  std::cout << " " << KEYSTA << "parent" << KEYEND << "\"" << PARENTDECL << "\"\n"; \
80  std::cout << "},\n"; \
81  }
82 
83 #define PRINTDOC(TYPE, LUANAME, RETVAL, DECL) \
84  if (LuaBindingDoc::printBindings ()) { \
85  std::cout << "{ " << KEYSTA << "type" << KEYEND << " \"" << TYPE << "\",\n"; \
86  std::cout << " " << KEYSTA << "lua" << KEYEND << " \"" << LUANAME << "\",\n"; \
87  if (!(RETVAL).empty()) { \
88  std::cout << " " << KEYSTA << "ret" << KEYEND << " \"" << (RETVAL) << "\",\n"; \
89  } \
90  std::cout << " " << KEYSTA << "decl" << KEYEND << " \"" << DECL << "\"\n"; \
91  std::cout << "},\n"; \
92  }
93 
94 #define FUNDOC(TYPE, NAME, FUNCTOR) \
95  PRINTDOC(TYPE, _name << NAME, \
96  type_name< typename FuncTraits <FUNCTOR>::ReturnType >(), \
97  type_name< typename FuncTraits <FUNCTOR>::DeclType >())
98 
99 #define DATADOC(TYPE, NAME, FUNCTOR) \
100  PRINTDOC(TYPE, _name << NAME, \
101  std::string(), \
102  type_name< decltype(FUNCTOR) >())\
103 
104 
105 #else
106 
107 #define CLASSDOC(TYPE, LUANAME, DECL, PARENTDECL)
108 #define PRINTDOC(TYPE, LUANAME, RETVAL, DECL)
109 #define FUNDOC(TYPE, NAME, FUNCTOR)
110 #define DATADOC(TYPE, NAME, FUNCTOR)
111 
112 #endif
113 
120 {
121 private:
123 
124  lua_State* const L;
125  int mutable m_stackSize;
126 
127 private:
128  //============================================================================
134 #if 0
135  static int luaError (lua_State* L, std::string message)
136  {
137  assert (lua_isstring (L, lua_upvalueindex (1)));
138  std::string s;
139 
140  // Get information on the caller's caller to format the message,
141  // so the error appears to originate from the Lua source.
142  lua_Debug ar;
143  int result = lua_getstack (L, 2, &ar);
144  if (result != 0)
145  {
146  lua_getinfo (L, "Sl", &ar);
147  s = ar.short_src;
148  if (ar.currentline != -1)
149  {
150  // poor mans int to string to avoid <strstrream>.
152  s = s + ":" + lua_tostring (L, -1) + ": ";
153  lua_pop (L, 1);
154  }
155  }
156 
157  s = s + message;
158 
159  return luaL_error (L, s.c_str ());
160  }
161 #endif
162 
163  //----------------------------------------------------------------------------
167  void pop (int n) const
168  {
169  if (m_stackSize >= n && lua_gettop (L) >= n)
170  {
171  lua_pop (L, n);
172  m_stackSize -= n;
173  }
174  else
175  {
176  throw std::logic_error ("invalid stack");
177  }
178  }
179 
180 private:
184  class ClassBase
185  {
186  private:
188 
189  protected:
190  friend class Namespace;
191 
192  lua_State* const L;
193  int mutable m_stackSize;
194 
195 #ifdef LUABINDINGDOC
196  std::string _name;
197  const Namespace* _parent;
198 #endif
199 
200  protected:
201  //--------------------------------------------------------------------------
213  {
214  int result = 0;
215 
216  assert (lua_isuserdata (L, 1)); // warn on security bypass
217  lua_getmetatable (L, 1); // get metatable for object
218  for (;;)
219  {
220  lua_pushvalue (L, 2); // push key arg2
221  lua_rawget (L, -2); // lookup key in metatable
222  if (lua_iscfunction (L, -1)) // ensure its a cfunction
223  {
224  lua_remove (L, -2); // remove metatable
225  result = 1;
226  break;
227  }
228  else if (lua_isnil (L, -1))
229  {
230  lua_pop (L, 1);
231  }
232  else
233  {
234  lua_pop (L, 2);
235  throw std::logic_error ("not a cfunction");
236  }
237 
238  rawgetfield (L, -1, "__propget"); // get __propget table
239  if (lua_istable (L, -1)) // ensure it is a table
240  {
241  lua_pushvalue (L, 2); // push key arg2
242  lua_rawget (L, -2); // lookup key in __propget
243  lua_remove (L, -2); // remove __propget
244  if (lua_iscfunction (L, -1)) // ensure its a cfunction
245  {
246  lua_remove (L, -2); // remove metatable
247  lua_pushvalue (L, 1); // push class arg1
248  lua_call (L, 1, 1);
249  result = 1;
250  break;
251  }
252  else if (lua_isnil (L, -1))
253  {
254  lua_pop (L, 1);
255  }
256  else
257  {
258  lua_pop (L, 2);
259 
260  // We only put cfunctions into __propget.
261  throw std::logic_error ("not a cfunction");
262  }
263  }
264  else
265  {
266  lua_pop (L, 2);
267 
268  // __propget is missing, or not a table.
269  throw std::logic_error ("missing __propget table");
270  }
271 
272  // Repeat the lookup in the __parent metafield,
273  // or return nil if the field doesn't exist.
274  rawgetfield (L, -1, "__parent");
275  if (lua_istable (L, -1))
276  {
277  // Remove metatable and repeat the search in __parent.
278  lua_remove (L, -2);
279  }
280  else if (lua_isnil (L, -1))
281  {
282  result = 1;
283  break;
284  }
285  else
286  {
287  lua_pop (L, 2);
288 
289  throw std::logic_error ("__parent is not a table");
290  }
291  }
292 
293  return result;
294  }
295 
296  //--------------------------------------------------------------------------
304  {
305  int result = 0;
306 
307  lua_getmetatable (L, 1);
308 
309  for (;;)
310  {
311  // Check __propset
312  rawgetfield (L, -1, "__propset");
313  if (!lua_isnil (L, -1))
314  {
315  lua_pushvalue (L, 2);
316  lua_rawget (L, -2);
317  if (!lua_isnil (L, -1))
318  {
319  // found it, call the setFunction.
320  assert (lua_isfunction (L, -1));
321  lua_pushvalue (L, 1);
322  lua_pushvalue (L, 3);
323  lua_call (L, 2, 0);
324  result = 0;
325  break;
326  }
327  lua_pop (L, 1);
328  }
329  lua_pop (L, 1);
330 
331  // Repeat the lookup in the __parent metafield.
332  rawgetfield (L, -1, "__parent");
333  if (lua_isnil (L, -1))
334  {
335  // Either the property or __parent must exist.
336  result = luaL_error (L,
337  "no member named '%s'", lua_tostring (L, 2));
338  }
339  lua_remove (L, -2);
340  }
341 
342  return result;
343  }
344 
345  //--------------------------------------------------------------------------
349  void createConstTable (char const* name)
350  {
351  lua_newtable (L);
352  lua_pushvalue (L, -1);
353  lua_setmetatable (L, -2);
354  lua_pushboolean (L, 1);
355  lua_rawsetp (L, -2, getIdentityKey ());
356  lua_pushstring (L, (std::string ("const ") + name).c_str ());
357  rawsetfield (L, -2, "__type");
359  rawsetfield (L, -2, "__index");
361  rawsetfield (L, -2, "__newindex");
362  lua_newtable (L);
363  rawsetfield (L, -2, "__propget");
364 
365  if (Security::hideMetatables ())
366  {
367  lua_pushboolean (L, false);
368  rawsetfield (L, -2, "__metatable");
369  }
370  }
371 
372  //--------------------------------------------------------------------------
378  void createClassTable (char const* name)
379  {
380  lua_newtable (L);
381  lua_pushvalue (L, -1);
382  lua_setmetatable (L, -2);
383  lua_pushboolean (L, 1);
384  lua_rawsetp (L, -2, getIdentityKey ());
385  lua_pushstring (L, name);
386  rawsetfield (L, -2, "__type");
388  rawsetfield (L, -2, "__index");
390  rawsetfield (L, -2, "__newindex");
391  lua_newtable (L);
392  rawsetfield (L, -2, "__propget");
393  lua_newtable (L);
394  rawsetfield (L, -2, "__propset");
395 
396  lua_pushvalue (L, -2);
397  rawsetfield (L, -2, "__const"); // point to const table
398 
399  lua_pushvalue (L, -1);
400  rawsetfield (L, -3, "__class"); // point const table to class table
401 
402  if (Security::hideMetatables ())
403  {
404  lua_pushboolean (L, false);
405  rawsetfield (L, -2, "__metatable");
406  }
407  }
408 
409  //--------------------------------------------------------------------------
418  void createStaticTable (char const* name)
419  {
420  lua_newtable (L);
421  lua_newtable (L);
422  lua_pushvalue (L, -1);
423  lua_setmetatable (L, -3);
424  lua_insert (L, -2);
425  rawsetfield (L, -5, name);
426 
427 #if 0
428  lua_pushlightuserdata (L, this);
429  lua_pushcclosure (L, &tostringMetaMethod, 1);
430  rawsetfield (L, -2, "__tostring");
431 #endif
433  rawsetfield (L, -2, "__index");
435  rawsetfield (L, -2, "__newindex");
436  lua_newtable (L);
437  rawsetfield (L, -2, "__propget");
438  lua_newtable (L);
439  rawsetfield (L, -2, "__propset");
440 
441  lua_pushvalue (L, -2);
442  rawsetfield (L, -2, "__class"); // point to class table
443 
444  if (Security::hideMetatables ())
445  {
446  lua_pushboolean (L, false);
447  rawsetfield (L, -2, "__metatable");
448  }
449  }
450 
451  //==========================================================================
455  template <class Params, class C>
457  {
458  typedef typename ContainerTraits <C>::Type T;
459  ArgList <Params, 2> args (L);
460  T* const p = Constructor <T, Params>::call (args);
462  return 1;
463  }
464 
465  //--------------------------------------------------------------------------
469  template <class Params, class T>
471  {
472  ArgList <Params, 2> args (L);
474  return 1;
475  }
476 
477  template <class Params, class T, class C>
479  {
480  ArgList <Params, 2> args (L);
481  T newobject (Constructor <C, Params>::call (args));
482  Stack<T>::push (L, newobject);
483  return 1;
484  }
485 
486  template <class T>
488  {
489  const T newobject;
490  Stack<T>::push (L, newobject);
491  return 1;
492  }
493 
494  //--------------------------------------------------------------------------
498  void pop (int n) const
499  {
500  if (m_stackSize >= n && lua_gettop (L) >= n)
501  {
502  lua_pop (L, n);
503  m_stackSize -= n;
504  }
505  else
506  {
507  throw std::logic_error ("invalid stack");
508  }
509  }
510 
511  public:
512  //--------------------------------------------------------------------------
513  explicit ClassBase (lua_State* L_)
514  : L (L_)
515  , m_stackSize (0)
516  {
517  }
518 
519  //--------------------------------------------------------------------------
523  ClassBase (ClassBase const& other)
524  : L (other.L)
525  , m_stackSize (0)
526 #ifdef LUABINDINGDOC
527  , _name (other._name)
528  , _parent (other._parent)
529 #endif
530  {
531  m_stackSize = other.m_stackSize;
532  other.m_stackSize = 0;
533  }
534 
536  {
537  pop (m_stackSize);
538  }
539  };
540 
541  //============================================================================
542  //
543  // Class
544  //
545  //============================================================================
555  template <class T>
556  class Class : virtual public ClassBase
557  {
558  public:
559  //==========================================================================
563  Class (char const* name, Namespace const* parent) : ClassBase (parent->L)
564  {
565 #ifdef LUABINDINGDOC
566  _parent = parent;
567  _name = parent->_name + name + ":";
568 #endif
569  PRINTDOC ("[C] Class", parent->_name << name, std::string(), type_name <T>())
570  m_stackSize = parent->m_stackSize + 3;
571  parent->m_stackSize = 0;
572 
573  assert (lua_istable (L, -1));
574  rawgetfield (L, -1, name);
575 
576  if (lua_isnil (L, -1))
577  {
578  lua_pop (L, 1);
579 
581  lua_pushcfunction (L, &CFunc::gcMetaMethod <T>);
582  rawsetfield (L, -2, "__gc");
584  rawsetfield (L, -2, "__eq");
585 
587  lua_pushcfunction (L, &CFunc::gcMetaMethod <T>);
588  rawsetfield (L, -2, "__gc");
590  rawsetfield (L, -2, "__eq");
591 
593 
594  // Map T back to its tables.
595  lua_pushvalue (L, -1);
597  lua_pushvalue (L, -2);
599  lua_pushvalue (L, -3);
601  }
602  else
603  {
604  lua_pop (L, 1);
606  rawgetfield (L, -1, "__class");
607  rawgetfield (L, -1, "__const");
608 
609  // Reverse the top 3 stack elements
610  lua_insert (L, -3);
611  lua_insert (L, -2);
612  }
613  }
614 
615  //==========================================================================
619  Class (char const* name, Namespace const* parent, void const* const staticKey)
620  : ClassBase (parent->L)
621  {
622 #ifdef LUABINDINGDOC
623  _parent = parent;
624  _name = parent->_name + name + ":";
625 #endif
626  m_stackSize = parent->m_stackSize + 3;
627  parent->m_stackSize = 0;
628 
629  assert (lua_istable (L, -1));
630 
632  lua_pushcfunction (L, &CFunc::gcMetaMethod <T>);
633  rawsetfield (L, -2, "__gc");
635  rawsetfield (L, -2, "__eq");
636 
638  lua_pushcfunction (L, &CFunc::gcMetaMethod <T>);
639  rawsetfield (L, -2, "__gc");
641  rawsetfield (L, -2, "__eq");
642 
644 
645  lua_rawgetp (L, LUA_REGISTRYINDEX, staticKey);
646  assert (lua_istable (L, -1));
647  rawgetfield (L, -1, "__class");
648  assert (lua_istable (L, -1));
649  rawgetfield (L, -1, "__const");
650  assert (lua_istable (L, -1));
651 
652  rawsetfield (L, -6, "__parent");
653  rawsetfield (L, -4, "__parent");
654  rawsetfield (L, -2, "__parent");
655 
656  lua_pushvalue (L, -1);
658  lua_pushvalue (L, -2);
660  lua_pushvalue (L, -3);
662  }
663 
664  //--------------------------------------------------------------------------
669  {
670  return Namespace (this);
671  }
672 
673  //--------------------------------------------------------------------------
677  template <class U>
678  Class <T>& addStaticData (char const* name, U* pu, bool isWritable = true)
679  {
680  DATADOC ("Static Data Member", name, pu)
681  assert (lua_istable (L, -1));
682 
683  rawgetfield (L, -1, "__propget");
684  assert (lua_istable (L, -1));
685  lua_pushlightuserdata (L, pu);
686  lua_pushcclosure (L, &CFunc::getVariable <U>, 1);
687  rawsetfield (L, -2, name);
688  lua_pop (L, 1);
689 
690  rawgetfield (L, -1, "__propset");
691  assert (lua_istable (L, -1));
692  if (isWritable)
693  {
694  lua_pushlightuserdata (L, pu);
695  lua_pushcclosure (L, &CFunc::setVariable <U>, 1);
696  }
697  else
698  {
699  lua_pushstring (L, name);
701  }
702  rawsetfield (L, -2, name);
703  lua_pop (L, 1);
704 
705  return *this;
706  }
707 
708  //--------------------------------------------------------------------------
709 #if 0 // unused
715  template <class U>
716  Class <T>& addStaticProperty (char const* name, U (*get)(), void (*set)(U) = 0)
717  {
718  typedef U (*get_t)();
719  typedef void (*set_t)(U);
720 
721  assert (lua_istable (L, -1));
722 
723  rawgetfield (L, -1, "__propget");
724  assert (lua_istable (L, -1));
725  new (lua_newuserdata (L, sizeof (get))) get_t (get);
726  lua_pushcclosure (L, &CFunc::Call <U (*) (void)>::f, 1);
727  rawsetfield (L, -2, name);
728  lua_pop (L, 1);
729 
730  rawgetfield (L, -1, "__propset");
731  assert (lua_istable (L, -1));
732  if (set != 0)
733  {
734  new (lua_newuserdata (L, sizeof (set))) set_t (set);
735  lua_pushcclosure (L, &CFunc::Call <void (*) (U)>::f, 1);
736  }
737  else
738  {
739  lua_pushstring (L, name);
741  }
742  rawsetfield (L, -2, name);
743  lua_pop (L, 1);
744 
745  return *this;
746  }
747 #endif
748 
752  Class <T>& addOperator (char const* name, int (*const fp)(lua_State*))
753  {
754  /* get metatable */
756  lua_pushcfunction (L, fp);
757  rawsetfield (L, -2, name);
758  lua_pop (L, 1);
759 
760  /* reset stack */
761  lua_pop (L, 3);
763  rawgetfield (L, -1, "__class");
764  rawgetfield (L, -1, "__const");
765  lua_insert (L, -3);
766  lua_insert (L, -2);
767 
768  return *this;
769  }
770 
774  template <class FP>
775  Class <T>& addMetamethod (char const* name, FP const fp)
776  {
777  /* get metatable */
779  new (lua_newuserdata (L, sizeof (FP))) FP (fp);
781  rawsetfield (L, -2, name);
782  lua_pop (L, 1);
783 
784  /* reset stack */
785  lua_pop (L, 3);
787  rawgetfield (L, -1, "__class");
788  rawgetfield (L, -1, "__const");
789  lua_insert (L, -3);
790  lua_insert (L, -2);
791 
792  return *this;
793  }
794 
795  //--------------------------------------------------------------------------
799  template <class FP>
800  Class <T>& addStaticFunction (char const* name, FP const fp)
801  {
802  FUNDOC ("Static Member Function", name, FP)
803  new (lua_newuserdata (L, sizeof (fp))) FP (fp);
805  rawsetfield (L, -2, name);
806 
807  return *this;
808  }
809 
810  //--------------------------------------------------------------------------
814  Class <T>& addStaticCFunction (char const* name, int (*const fp)(lua_State*))
815  {
816  DATADOC ("Static C Function", name, fp)
817  lua_pushcfunction (L, fp);
818  rawsetfield (L, -2, name);
819  return *this;
820  }
821 
822  //--------------------------------------------------------------------------
826  template <class U>
827  Class <T>& addData (char const* name, const U T::* mp, bool isWritable = true)
828  {
829  DATADOC ("Data Member", name, mp)
830  typedef const U T::*mp_t;
831 
832  // Add to __propget in class and const tables.
833  {
834  rawgetfield (L, -2, "__propget");
835  rawgetfield (L, -4, "__propget");
836  new (lua_newuserdata (L, sizeof (mp_t))) mp_t (mp);
837  lua_pushcclosure (L, &CFunc::getProperty <T,U>, 1);
838  lua_pushvalue (L, -1);
839  rawsetfield (L, -4, name);
840  rawsetfield (L, -2, name);
841  lua_pop (L, 2);
842  }
843 
844  if (isWritable)
845  {
846  // Add to __propset in class table.
847  rawgetfield (L, -2, "__propset");
848  assert (lua_istable (L, -1));
849  new (lua_newuserdata (L, sizeof (mp_t))) mp_t (mp);
850  lua_pushcclosure (L, &CFunc::setProperty <T,U>, 1);
851  rawsetfield (L, -2, name);
852  lua_pop (L, 1);
853  }
854 
855  return *this;
856  }
857 
858  //--------------------------------------------------------------------------
862  template <class TG, class TS>
863  Class <T>& addProperty (char const* name, TG (T::* get) () const, bool (T::* set) (TS))
864  {
865  DATADOC ("Property", name, get)
866  // Add to __propget in class and const tables.
867  {
868  rawgetfield (L, -2, "__propget");
869  rawgetfield (L, -4, "__propget");
870  typedef TG (T::*get_t) () const;
871  new (lua_newuserdata (L, sizeof (get_t))) get_t (get);
873  lua_pushvalue (L, -1);
874  rawsetfield (L, -4, name);
875  rawsetfield (L, -2, name);
876  lua_pop (L, 2);
877  }
878 
879  {
880  // Add to __propset in class table.
881  rawgetfield (L, -2, "__propset");
882  assert (lua_istable (L, -1));
883  typedef bool (T::* set_t) (TS);
884  new (lua_newuserdata (L, sizeof (set_t))) set_t (set);
886  rawsetfield (L, -2, name);
887  lua_pop (L, 1);
888  }
889 
890  return *this;
891  }
892 
893 #if 0 // unused
894  // read-only
895  template <class TG>
896  Class <T>& addProperty (char const* name, TG (T::* get) () const)
897  {
898  // Add to __propget in class and const tables.
899  rawgetfield (L, -2, "__propget");
900  rawgetfield (L, -4, "__propget");
901  typedef TG (T::*get_t) () const;
902  new (lua_newuserdata (L, sizeof (get_t))) get_t (get);
904  lua_pushvalue (L, -1);
905  rawsetfield (L, -4, name);
906  rawsetfield (L, -2, name);
907  lua_pop (L, 2);
908 
909  return *this;
910  }
911 #endif
912 
913  //--------------------------------------------------------------------------
924  template <class TG, class TS>
925  Class <T>& addProperty (char const* name, TG (*get) (T const*), bool (*set) (T*, TS))
926  {
927  // Add to __propget in class and const tables.
928  {
929  rawgetfield (L, -2, "__propget");
930  rawgetfield (L, -4, "__propget");
931  typedef TG (*get_t) (T const*);
932  new (lua_newuserdata (L, sizeof (get_t))) get_t (get);
934  lua_pushvalue (L, -1);
935  rawsetfield (L, -4, name);
936  rawsetfield (L, -2, name);
937  lua_pop (L, 2);
938  }
939 
940  if (set != 0)
941  {
942  // Add to __propset in class table.
943  rawgetfield (L, -2, "__propset");
944  assert (lua_istable (L, -1));
945  typedef void (*set_t) (T*, TS);
946  new (lua_newuserdata (L, sizeof (set_t))) set_t (set);
948  rawsetfield (L, -2, name);
949  lua_pop (L, 1);
950  }
951 
952  return *this;
953  }
954 
955 #if 0 // unused
956  // read-only
957  template <class TG, class TS>
958  Class <T>& addProperty (char const* name, TG (*get) (T const*))
959  {
960  // Add to __propget in class and const tables.
961  rawgetfield (L, -2, "__propget");
962  rawgetfield (L, -4, "__propget");
963  typedef TG (*get_t) (T const*);
964  new (lua_newuserdata (L, sizeof (get_t))) get_t (get);
966  lua_pushvalue (L, -1);
967  rawsetfield (L, -4, name);
968  rawsetfield (L, -2, name);
969  lua_pop (L, 2);
970 
971  return *this;
972  }
973 #endif
974  //--------------------------------------------------------------------------
978  template <class MemFn>
979  Class <T>& addFunction (char const* name, MemFn mf)
980  {
981  FUNDOC("Member Function", name, MemFn)
983  return *this;
984  }
985 
986  template <class MemFn>
987  Class <T>& addPtrFunction (char const* name, MemFn mf)
988  {
989  FUNDOC("Member Pointer Function", name, MemFn)
991  return *this;
992  }
993 
994  template <class MemFn>
995  Class <T>& addWPtrFunction (char const* name, MemFn mf)
996  {
997  FUNDOC("Member Weak Pointer Function", name, MemFn)
999  return *this;
1000  }
1001 
1002  template <class MemFn>
1003  Class <T>& addRefFunction (char const* name, MemFn mf)
1004  {
1005  FUNDOC("Member Function RefReturn", name, MemFn)
1007  return *this;
1008  }
1009 
1010 
1011  //--------------------------------------------------------------------------
1015  Class <T>& addCFunction (char const* name, int (T::*mfp)(lua_State*))
1016  {
1017  DATADOC ("C Function", name, mfp)
1018  typedef int (T::*MFP)(lua_State*);
1019  assert (lua_istable (L, -1));
1020  new (lua_newuserdata (L, sizeof (mfp))) MFP (mfp);
1022  rawsetfield (L, -3, name); // class table
1023 
1024  return *this;
1025  }
1026 
1027  // custom callback - extend existing classes
1028  // with non-class member functions (e.g STL iterator)
1029  Class <T>& addExtCFunction (char const* name, int (*const fp)(lua_State*))
1030  {
1031  DATADOC ("Ext C Function", name, fp)
1032  assert (lua_istable (L, -1));
1033  lua_pushcclosure (L, fp, 0);
1034  lua_pushvalue (L, -1);
1035  rawsetfield (L, -5, name); // const table
1036  rawsetfield (L, -3, name); // class table
1037  return *this;
1038  }
1039 
1040  //--------------------------------------------------------------------------
1044  Class <T>& addCFunction (char const* name, int (T::*mfp)(lua_State*) const)
1045  {
1046  DATADOC ("Const C Member Function", name, mfp)
1047  typedef int (T::*MFP)(lua_State*) const;
1048  assert (lua_istable (L, -1));
1049  new (lua_newuserdata (L, sizeof (mfp))) MFP (mfp);
1051  lua_pushvalue (L, -1);
1052  rawsetfield (L, -5, name); // const table
1053  rawsetfield (L, -3, name); // class table
1054 
1055  return *this;
1056  }
1057 
1061  template <typename U>
1062  Class <T>& addConst (char const* name, const U val)
1063  {
1064  DATADOC ("Constant/Enum Member", name, val)
1065  assert (lua_istable (L, -1));
1066 
1067  rawgetfield (L, -1, "__propget"); // static
1068  new (lua_newuserdata (L, sizeof (val))) U (val);
1069  lua_pushcclosure (L, &CFunc::getConst <U>, 1);
1070  rawsetfield (L, -2, name);
1071  lua_pop (L, 1);
1072 
1073  rawgetfield (L, -1, "__propset"); // static
1074  lua_pushstring (L, name);
1076  rawsetfield (L, -2, name);
1077  lua_pop (L, 1);
1078  return *this;
1079  }
1080 
1081  //--------------------------------------------------------------------------
1092  template <class MemFn, class C>
1094  {
1095  FUNDOC("Constructor", "", MemFn)
1098  rawsetfield(L, -2, "__call");
1099 
1100  return *this;
1101  }
1102 
1103  template <class MemFn>
1105  {
1106  FUNDOC("Constructor", "", MemFn)
1109  rawsetfield(L, -2, "__call");
1110 
1111  return *this;
1112  }
1113 
1114  template <class MemFn, class PT>
1116  {
1117  FUNDOC("Constructor", "", MemFn)
1119  &ctorPtrPlacementProxy <typename FuncTraits <MemFn>::Params, T, PT>, 0);
1120  rawsetfield(L, -2, "__call");
1121 
1122  return *this;
1123  }
1124 
1126  {
1127  return addConstructor <void (*) ()> ();
1128  }
1129 
1130  template <class PT>
1132  {
1133  return addPtrConstructor <void (*) (), PT> ();
1134  }
1135 
1137  {
1138  assert (lua_istable (L, -1));
1140  rawsetfield (L, -3, "sameinstance");
1141  return *this;
1142  }
1143 
1144  template <class U>
1145  Class <T>& addCast (char const* name)
1146  {
1147  PRINTDOC("Cast", _name << name,
1148  type_name< U >(),
1149  type_name< U >() << " (" << type_name< T >() << "::*)()")
1150 
1151  assert (lua_istable (L, -1));
1153  rawsetfield (L, -3, name); // class table
1154 
1156  rawsetfield (L, -4, name); // const table
1157  return *this;
1158  }
1159 
1160  };
1161 
1163  template <typename T>
1164  class Array : virtual public ClassBase
1165  {
1166  public:
1167  Array (char const* name, Namespace const* parent) : ClassBase (parent->L)
1168  {
1169 #ifdef LUABINDINGDOC
1170  _parent = parent;
1171  _name = parent->_name + name + ":";
1172 #endif
1173  PRINTDOC ("[C] Array", parent->_name << name,
1174  std::string(), type_name <T>() + "*")
1175  PRINTDOC ("Ext C Function", _name << "array",
1176  std::string(""), "int (*)(lua_State*)")
1177  PRINTDOC ("Ext C Function", _name << "get_table",
1178  std::string(""), "int (*)(lua_State*)")
1179  PRINTDOC ("Ext C Function", _name << "set_table",
1180  std::string(""), "int (*)(lua_State*)")
1181  PRINTDOC("Member Function", _name << "offset",
1182  std::string(type_name <T>() + "*"), std::string(type_name <T>() + "* (*)(unsigned int)"))
1183 
1184  m_stackSize = parent->m_stackSize + 3;
1185  parent->m_stackSize = 0;
1186 
1187 #if 0 // don't allow to duplicates handlers for same array-type
1188  assert (lua_istable (L, -1));
1190  if (lua_istable (L, -1)) {
1191  lua_pushnil (L);
1192  lua_pushnil (L);
1193  return;
1194  }
1195  lua_pop (L, 1);
1196 #endif
1197 
1198  assert (lua_istable (L, -1));
1199  rawgetfield (L, -1, name);
1200 
1201  if (lua_isnil (L, -1))
1202  {
1203  lua_pop (L, 1);
1204 
1205  // register array access in global namespace
1206  luaL_newmetatable (L, typeid(T).name());
1207  lua_pushcclosure (L, CFunc::array_index<T>, 0);
1208  lua_setfield(L, -2, "__index");
1209  lua_pushcclosure (L, CFunc::array_newindex<T>, 0);
1210  lua_setfield(L, -2, "__newindex");
1211  if (Security::hideMetatables ())
1212  {
1213  lua_pushboolean (L, false);
1214  rawsetfield (L, -2, "__metatable");
1215  }
1216  lua_pop (L, 1);
1217 
1218 
1220  lua_pushcfunction (L, &CFunc::gcMetaMethod <T>);
1221  rawsetfield (L, -2, "__gc");
1223  rawsetfield (L, -2, "__eq");
1224 
1226  lua_pushcfunction (L, &CFunc::gcMetaMethod <T>);
1227  rawsetfield (L, -2, "__gc");
1229  rawsetfield (L, -2, "__eq");
1230 
1232 
1233  // Map T back to its tables.
1234  lua_pushvalue (L, -1);
1236  lua_pushvalue (L, -2);
1238  lua_pushvalue (L, -3);
1240 
1241  assert (lua_istable (L, -1));
1242  lua_pushcclosure (L, &CFunc::getArray <T>, 0);
1243  rawsetfield (L, -3, "array"); // class table
1244 
1245  lua_pushcclosure (L, &CFunc::getTable <T>, 0);
1246  rawsetfield (L, -3, "get_table"); // class table
1247 
1248  lua_pushcclosure (L, &CFunc::setTable <T>, 0);
1249  rawsetfield (L, -3, "set_table"); // class table
1250 
1252  rawsetfield (L, -3, "sameinstance");
1253 
1254  lua_pushcclosure (L, &CFunc::offsetArray <T>, 0);
1255  rawsetfield (L, -3, "offset"); // class table
1256 
1257  }
1258  else
1259  {
1260  lua_pushnil (L);
1261  lua_pushnil (L);
1262  }
1263  }
1264 
1266  {
1267  return Namespace (this);
1268  }
1269  };
1270 
1272  template <class T>
1273  class WSPtrClass : virtual public ClassBase
1274  {
1275  public:
1276  WSPtrClass (char const* name, Namespace const* parent)
1277  : ClassBase (parent->L)
1278  , shared (name, parent)
1279  , shared_const (name, parent)
1280  , weak (name, parent)
1281  {
1282 #ifdef LUABINDINGDOC
1283  _parent = parent;
1284  _name = parent->_name + name + ":";
1285 #endif
1286  PRINTDOC ("[C] Weak/Shared Pointer Class",
1287  parent->_name + name,
1288  std::string(), type_name <T>())
1291  lua_pop (L, 6);
1292  }
1293 
1294  WSPtrClass (char const* name, Namespace const* parent, void const* const sharedkey, void const* const sharedconstkey, void const* const weakkey)
1295  : ClassBase (parent->L)
1296  , shared (name, parent, sharedkey)
1297  , shared_const (name, parent, sharedconstkey)
1298  , weak (name, parent, weakkey)
1299  {
1300 #ifdef LUABINDINGDOC
1301  _parent = parent;
1302  _name = parent->_name + name + ":";
1303 #endif
1306  lua_pop (L, 6);
1307  }
1308 
1309  template <class MemFn>
1310  WSPtrClass <T>& addFunction (char const* name, MemFn mf)
1311  {
1312  FUNDOC ("Weak/Shared Pointer Function", name, MemFn)
1313  set_shared_class ();
1315 
1318 
1319  set_weak_class ();
1321  return *this;
1322  }
1323 
1324  template <class MemFn>
1325  WSPtrClass <T>& addRefFunction (char const* name, MemFn mf)
1326  {
1327  FUNDOC ("Weak/Shared Pointer Function RefReturn", name, MemFn)
1328  set_shared_class ();
1330 
1333 
1334  set_weak_class ();
1336  return *this;
1337  }
1338 
1339  template <class MemFn>
1341  {
1342  FUNDOC ("Weak/Shared Pointer Constructor", "", MemFn)
1343  set_shared_class ();
1345  &shared. template ctorPtrPlacementProxy <typename FuncTraits <MemFn>::Params, std::shared_ptr<T>, T >, 0);
1346  rawsetfield(L, -2, "__call");
1347 
1350  &shared_const. template ctorPtrPlacementProxy <typename FuncTraits <MemFn>::Params, std::shared_ptr<T const>, T >, 0);
1351  rawsetfield(L, -2, "__call");
1352 
1353  set_weak_class ();
1354  // NOTE: this constructs an empty weak-ptr,
1355  // ideally we'd construct a weak-ptr from a referenced shared-ptr
1357  &weak. template ctorPlacementProxy <typename FuncTraits <MemFn>::Params, std::weak_ptr<T> >, 0);
1358  rawsetfield(L, -2, "__call");
1359  return *this;
1360  }
1361 
1363  {
1364  return addConstructor <void (*) ()> ();
1365  }
1366 
1367  template <class FP>
1368  WSPtrClass <T>& addStaticFunction (char const* name, FP const fp)
1369  {
1370  FUNDOC ("Static Member Function", name, FP)
1371  set_shared_class ();
1372  new (lua_newuserdata (L, sizeof (fp))) FP (fp);
1374  rawsetfield (L, -2, name);
1375 
1377  new (lua_newuserdata (L, sizeof (fp))) FP (fp);
1379  rawsetfield (L, -2, name);
1380 
1381  set_weak_class ();
1382  new (lua_newuserdata (L, sizeof (fp))) FP (fp);
1384  rawsetfield (L, -2, name);
1385  return *this;
1386  }
1387 
1389  {
1390  FUNDOC ("Weak/Shared Pointer NIL Constructor", "", void (*) ())
1391  set_shared_class ();
1393  &shared. template ctorNilPtrPlacementProxy <std::shared_ptr<T> >, 0);
1394  rawsetfield(L, -2, "__call");
1395 
1398  &shared_const. template ctorNilPtrPlacementProxy <std::shared_ptr<T const> >, 0);
1399  rawsetfield(L, -2, "__call");
1400 
1401  set_weak_class ();
1402  // NOTE: this constructs an empty weak-ptr,
1403  // ideally we'd construct a weak-ptr from a referenced shared-ptr
1405  &weak. template ctorNilPtrPlacementProxy <std::weak_ptr<T> >, 0);
1406  rawsetfield(L, -2, "__call");
1407 
1408  return *this;
1409  }
1410 
1411  WSPtrClass <T>& addExtCFunction (char const* name, int (*const fp)(lua_State*))
1412  {
1413  DATADOC ("Weak/Shared Ext C Function", name, fp)
1414  set_shared_class ();
1415  assert (lua_istable (L, -1));
1416  lua_pushcclosure (L, fp, 0);
1417  lua_pushvalue (L, -1);
1418  rawsetfield (L, -5, name); // const table
1419  rawsetfield (L, -3, name); // class table
1420 
1422  assert (lua_istable (L, -1));
1423  lua_pushcclosure (L, fp, 0);
1424  lua_pushvalue (L, -1);
1425  rawsetfield (L, -5, name); // const table
1426  rawsetfield (L, -3, name); // class table
1427 
1428  set_weak_class ();
1429  assert (lua_istable (L, -1));
1430  lua_pushcclosure (L, fp, 0);
1431  lua_pushvalue (L, -1);
1432  rawsetfield (L, -5, name); // const table
1433  rawsetfield (L, -3, name); // class table
1434 
1435  return *this;
1436  }
1437 
1438  template <class U>
1439  WSPtrClass <T>& addCast (char const* name)
1440  {
1441  PRINTDOC("Weak/Shared Pointer Cast", _name << name,
1442  type_name< U >(),
1443  type_name< U >() << " (" << type_name< T >() << "::*)()")
1444 
1445  // TODO weak ptr
1446  set_shared_class ();
1447  assert (lua_istable (L, -1));
1449  rawsetfield (L, -3, name); // class table
1450 
1452  assert (lua_istable (L, -1));
1454  rawsetfield (L, -3, name); // class table
1455 
1456  return *this;
1457  }
1458 
1460  {
1461  PRINTDOC("Weak/Shared Null Check", _name << "isnil", std::string("bool"), std::string("void (*)()"))
1462  set_shared_class ();
1463  assert (lua_istable (L, -1));
1465  rawsetfield (L, -3, "isnil"); // class table
1466 
1468  assert (lua_istable (L, -1));
1470  rawsetfield (L, -3, "isnil"); // class table
1471 
1472  set_weak_class ();
1473  assert (lua_istable (L, -1));
1475  rawsetfield (L, -3, "isnil"); // class table
1476 
1477  return *this;
1478  }
1479 
1481  {
1482  set_shared_class ();
1483  assert (lua_istable (L, -1));
1485  rawsetfield (L, -3, "sameinstance"); // class table
1486 
1488  assert (lua_istable (L, -1));
1490  rawsetfield (L, -3, "sameinstance"); // class table
1491 
1492  set_weak_class ();
1493  assert (lua_istable (L, -1));
1495  rawsetfield (L, -3, "sameinstance"); // class table
1496 
1497  return *this;
1498  }
1499 
1500  template <class U>
1501  WSPtrClass <T>& addData (char const* name, const U T::* mp, bool isWritable = true)
1502  {
1503  DATADOC ("Data Member", name, mp)
1504  typedef const U T::*mp_t;
1505 
1506  set_weak_class ();
1507  assert (lua_istable (L, -1));
1508  // Add to __propget in class and const tables.
1509  {
1510  rawgetfield (L, -2, "__propget");
1511  rawgetfield (L, -4, "__propget");
1512  new (lua_newuserdata (L, sizeof (mp_t))) mp_t (mp);
1513  lua_pushcclosure (L, &CFunc::getWPtrProperty <T,U>, 1);
1514  lua_pushvalue (L, -1);
1515  rawsetfield (L, -4, name);
1516  rawsetfield (L, -2, name);
1517  lua_pop (L, 2);
1518  }
1519 
1520  if (isWritable)
1521  {
1522  // Add to __propset in class table.
1523  rawgetfield (L, -2, "__propset");
1524  assert (lua_istable (L, -1));
1525  new (lua_newuserdata (L, sizeof (mp_t))) mp_t (mp);
1526  lua_pushcclosure (L, &CFunc::setWPtrProperty <T,U>, 1);
1527  rawsetfield (L, -2, name);
1528  lua_pop (L, 1);
1529  }
1530 
1532  assert (lua_istable (L, -1));
1533  // Add to __propget in class and const tables.
1534  {
1535  rawgetfield (L, -2, "__propget");
1536  rawgetfield (L, -4, "__propget");
1537  new (lua_newuserdata (L, sizeof (mp_t))) mp_t (mp);
1538  lua_pushcclosure (L, &CFunc::getPtrProperty <T const,U>, 1);
1539  lua_pushvalue (L, -1);
1540  rawsetfield (L, -4, name);
1541  rawsetfield (L, -2, name);
1542  lua_pop (L, 2);
1543  }
1544 
1545  set_shared_class ();
1546  assert (lua_istable (L, -1));
1547  // Add to __propget in class and const tables.
1548  {
1549  rawgetfield (L, -2, "__propget");
1550  rawgetfield (L, -4, "__propget");
1551  new (lua_newuserdata (L, sizeof (mp_t))) mp_t (mp);
1552  lua_pushcclosure (L, &CFunc::getPtrProperty <T,U>, 1);
1553  lua_pushvalue (L, -1);
1554  rawsetfield (L, -4, name);
1555  rawsetfield (L, -2, name);
1556  lua_pop (L, 2);
1557  }
1558 
1559  if (isWritable)
1560  {
1561  // Add to __propset in class table.
1562  rawgetfield (L, -2, "__propset");
1563  assert (lua_istable (L, -1));
1564  new (lua_newuserdata (L, sizeof (mp_t))) mp_t (mp);
1565  lua_pushcclosure (L, &CFunc::setPtrProperty <T,U>, 1);
1566  rawsetfield (L, -2, name);
1567  lua_pop (L, 1);
1568  }
1569 
1570  return *this;
1571  }
1572 
1573 
1575  {
1576  return Namespace (this);
1577  }
1578 
1579  private:
1580  void set_weak_class () {
1581  lua_pop (L, 3);
1582  lua_rawgetp (L, LUA_REGISTRYINDEX, ClassInfo <std::weak_ptr<T> >::getStaticKey ());
1583  rawgetfield (L, -1, "__class");
1584  rawgetfield (L, -1, "__const");
1585  lua_insert (L, -3);
1586  lua_insert (L, -2);
1587  }
1589  lua_pop (L, 3);
1590  lua_rawgetp (L, LUA_REGISTRYINDEX, ClassInfo <std::shared_ptr<T> >::getStaticKey ());
1591  rawgetfield (L, -1, "__class");
1592  rawgetfield (L, -1, "__const");
1593  lua_insert (L, -3);
1594  lua_insert (L, -2);
1595  }
1597  lua_pop (L, 3);
1598  lua_rawgetp (L, LUA_REGISTRYINDEX, ClassInfo <std::shared_ptr<T const> >::getStaticKey ());
1599  rawgetfield (L, -1, "__class");
1600  rawgetfield (L, -1, "__const");
1601  lua_insert (L, -3);
1602  lua_insert (L, -2);
1603  }
1604 
1608  };
1609 
1610 
1611 private:
1612  //----------------------------------------------------------------------------
1616  explicit Namespace (lua_State* L_)
1617  : L (L_)
1618  , m_stackSize (0)
1619 #ifdef LUABINDINGDOC
1620  , _name ("")
1621  , _parent (0)
1622 #endif
1623  {
1624  lua_getglobal (L, "_G");
1625  ++m_stackSize;
1626  }
1627 
1628 #ifdef LUABINDINGDOC
1629  std::string _name;
1630  Namespace const * _parent;
1631 #endif
1632 
1633  //----------------------------------------------------------------------------
1640  Namespace (char const* name, Namespace const* parent)
1641  : L (parent->L)
1642  , m_stackSize (0)
1643 #ifdef LUABINDINGDOC
1644  , _name (parent->_name + name + ":")
1645  , _parent (parent)
1646 #endif
1647  {
1648  m_stackSize = parent->m_stackSize + 1;
1649  parent->m_stackSize = 0;
1650 
1651  assert (lua_istable (L, -1));
1652  rawgetfield (L, -1, name);
1653  if (lua_isnil (L, -1))
1654  {
1655  lua_pop (L, 1);
1656 
1657  lua_newtable (L);
1658  lua_pushvalue (L, -1);
1659  lua_setmetatable (L, -2);
1661  rawsetfield (L, -2, "__index");
1663  rawsetfield (L, -2, "__newindex");
1664  lua_newtable (L);
1665  rawsetfield (L, -2, "__propget");
1666  lua_newtable (L);
1667  rawsetfield (L, -2, "__propset");
1668  lua_pushvalue (L, -1);
1669  rawsetfield (L, -3, name);
1670 #if 0
1671  lua_pushcfunction (L, &tostringMetaMethod);
1672  rawsetfield (L, -2, "__tostring");
1673 #endif
1674  if (Security::hideMetatables ())
1675  {
1676  lua_pushboolean (L, false);
1677  rawsetfield (L, -2, "__metatable");
1678  }
1679 
1680  }
1681  }
1682 
1683  //----------------------------------------------------------------------------
1687  explicit Namespace (Namespace const* child)
1688  : L (child->L)
1689  , m_stackSize (0)
1690 #ifdef LUABINDINGDOC
1691  , _name (child->_parent ? child->_parent->_name : "")
1692  , _parent (child->_parent ? child->_parent->_parent : NULL)
1693 #endif
1694  {
1695  m_stackSize = child->m_stackSize - 1;
1696  child->m_stackSize = 1;
1697  child->pop (1);
1698 
1699  // It is not necessary or valid to call
1700  // endNamespace() for the global namespace!
1701  //
1702  assert (m_stackSize != 0);
1703  }
1704 
1705  //----------------------------------------------------------------------------
1709  explicit Namespace (ClassBase const* child)
1710  : L (child->L)
1711  , m_stackSize (0)
1712 #ifdef LUABINDINGDOC
1713  , _name (child->_parent ? child->_parent->_name : "")
1714  , _parent (child->_parent ? child->_parent->_parent : NULL)
1715 #endif
1716  {
1717  m_stackSize = child->m_stackSize - 3;
1718  child->m_stackSize = 3;
1719  child->pop (3);
1720  }
1721 
1722 public:
1723  //----------------------------------------------------------------------------
1731  Namespace (Namespace const& other) : L (other.L)
1732  {
1733  m_stackSize = other.m_stackSize;
1734  other.m_stackSize = 0;
1735 #ifdef LUABINDINGDOC
1736  _name = other._name;
1737  _parent = other._parent;
1738 #endif
1739  }
1740 
1741  //----------------------------------------------------------------------------
1746  {
1747  pop (m_stackSize);
1748  }
1749 
1750  //----------------------------------------------------------------------------
1755  {
1756  return Namespace (L);
1757  }
1758 
1759  //----------------------------------------------------------------------------
1764  {
1765  return Namespace (name, this);
1766  }
1767 
1768  //----------------------------------------------------------------------------
1775  {
1776  return Namespace (this);
1777  }
1778 
1779  //----------------------------------------------------------------------------
1783  template <class T>
1784  Namespace& addVariable (char const* name, T* pt, bool isWritable = true)
1785  {
1786  assert (lua_istable (L, -1));
1787 
1788  rawgetfield (L, -1, "__propget");
1789  assert (lua_istable (L, -1));
1790  lua_pushlightuserdata (L, pt);
1791  lua_pushcclosure (L, &CFunc::getVariable <T>, 1);
1792  rawsetfield (L, -2, name);
1793  lua_pop (L, 1);
1794 
1795  rawgetfield (L, -1, "__propset");
1796  assert (lua_istable (L, -1));
1797  if (isWritable)
1798  {
1799  lua_pushlightuserdata (L, pt);
1800  lua_pushcclosure (L, &CFunc::setVariable <T>, 1);
1801  }
1802  else
1803  {
1804  lua_pushstring (L, name);
1806  }
1807  rawsetfield (L, -2, name);
1808  lua_pop (L, 1);
1809 
1810  return *this;
1811  }
1812 
1813  template <typename U>
1814  Namespace& addConst (char const* name, const U val)
1815  {
1816  DATADOC ("Constant/Enum", name, val)
1817  assert (lua_istable (L, -1));
1818  rawgetfield (L, -1, "__propget");
1819  new (lua_newuserdata (L, sizeof (val))) U (val);
1820  lua_pushcclosure (L, &CFunc::getConst <U>, 1);
1821  rawsetfield (L, -2, name);
1822  lua_pop (L, 1);
1823 
1824  rawgetfield (L, -1, "__propset");
1825  assert (lua_istable (L, -1));
1826  lua_pushstring (L, name);
1828  rawsetfield (L, -2, name);
1829  lua_pop (L, 1);
1830  return *this;
1831  }
1832 
1833  //----------------------------------------------------------------------------
1839 #if 0 // unused
1840  template <class TG, class TS>
1841  Namespace& addProperty (char const* name, TG (*get) (), void (*set)(TS) = 0)
1842  {
1843  assert (lua_istable (L, -1));
1844 
1845  rawgetfield (L, -1, "__propget");
1846  assert (lua_istable (L, -1));
1847  typedef TG (*get_t) ();
1848  new (lua_newuserdata (L, sizeof (get_t))) get_t (get);
1849  lua_pushcclosure (L, &CFunc::Call <TG (*) (void)>::f, 1);
1850  rawsetfield (L, -2, name);
1851  lua_pop (L, 1);
1852 
1853  rawgetfield (L, -1, "__propset");
1854  assert (lua_istable (L, -1));
1855  if (set != 0)
1856  {
1857  typedef void (*set_t) (TS);
1858  new (lua_newuserdata (L, sizeof (set_t))) set_t (set);
1859  lua_pushcclosure (L, &CFunc::Call <void (*) (TS)>::f, 1);
1860  }
1861  else
1862  {
1863  lua_pushstring (L, name);
1865  }
1866  rawsetfield (L, -2, name);
1867  lua_pop (L, 1);
1868 
1869  return *this;
1870  }
1871 #endif
1872 
1873  //----------------------------------------------------------------------------
1877  template <class FP>
1878  Namespace& addFunction (char const* name, FP const fp)
1879  {
1880  FUNDOC ("Free Function", name, FP)
1881  assert (lua_istable (L, -1));
1882 
1883  new (lua_newuserdata (L, sizeof (fp))) FP (fp);
1885  rawsetfield (L, -2, name);
1886 
1887  return *this;
1888  }
1889 
1890  template <class FP>
1891  Namespace& addRefFunction (char const* name, FP const fp)
1892  {
1893  FUNDOC ("Free Function RefReturn", name, FP)
1894  assert (lua_istable (L, -1));
1895 
1896  new (lua_newuserdata (L, sizeof (fp))) FP (fp);
1898  rawsetfield (L, -2, name);
1899 
1900  return *this;
1901  }
1902 
1903  //----------------------------------------------------------------------------
1908  template <typename T>
1910  {
1911  return Array <T> (name, this).endArray();
1912  }
1913 
1914 
1915  //----------------------------------------------------------------------------
1919  Namespace& addCFunction (char const* name, int (*const fp)(lua_State*))
1920  {
1921  DATADOC ("Free C Function", name, fp)
1922  lua_pushcfunction (L, fp);
1923  rawsetfield (L, -2, name);
1924 
1925  return *this;
1926  }
1927 
1928  //----------------------------------------------------------------------------
1932  template <class T>
1933  Class <T> beginClass (char const* name)
1934  {
1935  return Class <T> (name, this);
1936  }
1937 
1939  template <class T>
1941  {
1942  return WSPtrClass <T> (name, this)
1943  .addNullCheck()
1944  .addEqualCheck();
1945  }
1946 
1947  //----------------------------------------------------------------------------
1948 
1949  template <class K, class V>
1951  {
1952  typedef std::map<K, V> LT;
1953  typedef std::pair<const K, V> T;
1954 
1955  typedef typename std::map<K, V>::size_type T_SIZE;
1956 
1957  return beginClass<LT> (name)
1958  .addVoidConstructor ()
1959  .addFunction ("empty", (bool (LT::*)()const)&LT::empty)
1960  .addFunction ("size", (T_SIZE (LT::*)()const)&LT::size)
1961  .addFunction ("clear", (void (LT::*)())&LT::clear)
1962  .addFunction ("count", (T_SIZE (LT::*)(const K&) const)&LT::count)
1963  .addExtCFunction ("add", &CFunc::tableToMap<K, V>)
1964  .addExtCFunction ("iter", &CFunc::mapIter<K, V>)
1965  .addExtCFunction ("table", &CFunc::mapToTable<K, V>)
1966  .addExtCFunction ("at", &CFunc::mapAt<K, V>);
1967  }
1968 
1969  template <class T>
1971  {
1972  typedef std::set<T> LT;
1973  typedef typename LT::size_type T_SIZE;
1974  return beginClass<LT> (name)
1975  .addVoidConstructor ()
1976  .addFunction ("clear", (void (LT::*)())&LT::clear)
1977  .addFunction ("empty", (bool (LT::*)()const)&LT::empty)
1978  .addFunction ("size", (T_SIZE (LT::*)()const)&LT::size)
1979 #if 0 // needs work for AutomationTypeSet (T is-a enum not a class instance)
1980  .addExtCFunction ("insert", &CFunc::setInsert<T, LT>)
1981 #endif
1982  .addExtCFunction ("iter", &CFunc::setIter<T, LT>)
1983  .addExtCFunction ("table", &CFunc::setToTable<T, LT>);
1984  }
1985 
1986  template <unsigned int T>
1988  {
1989  typedef std::bitset<T> BS;
1990  return beginClass<BS> (name)
1991  .addVoidConstructor ()
1992  .addFunction ("reset", (BS& (BS::*)())&BS::reset)
1993  .addFunction ("set", (BS& (BS::*)(size_t, bool))&BS::set)
1994  .addFunction ("count", (size_t (BS::*)()const)&BS::count)
1995  .addFunction ("size", (size_t (BS::*)()const)&BS::size)
1996  .addFunction ("any", (bool (BS::*)()const)&BS::any)
1997  .addFunction ("none", (bool (BS::*)()const)&BS::none)
1998  .addFunction ("test", &BS::test)
1999  .addExtCFunction ("add", &CFunc::tableToBitSet<T>)
2000  .addExtCFunction ("table", &CFunc::bitSetToTable<T>);
2001  }
2002 
2003  template <class T>
2005  {
2006  typedef std::list<T> LT;
2007  typedef typename LT::size_type T_SIZE;
2008  return beginClass<LT> (name)
2009  .addVoidConstructor ()
2010  .addFunction ("empty", static_cast<bool (LT::*)() const>(&LT::empty))
2011  .addFunction ("size", static_cast<T_SIZE (LT::*)() const>(&LT::size))
2012  .addFunction ("reverse", static_cast<void (LT::*)()>(&LT::reverse))
2013  .addFunction ("front", static_cast<T& (LT::*)()>(&LT::front))
2014  .addFunction ("back", static_cast<T& (LT::*)()>(&LT::back))
2015  .addExtCFunction ("iter", &CFunc::listIter<T, LT>)
2016  .addExtCFunction ("table", &CFunc::listToTable<T, LT>);
2017  }
2018 
2019  template <class T>
2021  {
2022  typedef std::list<T> LT;
2023  typedef typename LT::size_type T_SIZE;
2024  return beginConstStdList<T> (name)
2025 #if !defined(_MSC_VER) || (_MSC_VER < 1900)
2026  /* std::list::unique() got broken in later versions of MSVC */
2027 # if (defined(__cplusplus) && __cplusplus >= 201709L)
2028  .addFunction ("unique", (T_SIZE (LT::*)())&LT::unique)
2029 # else
2030  .addFunction ("unique", (void (LT::*)())&LT::unique)
2031 # endif
2032 #endif
2033  .addFunction ("clear", (void (LT::*)())&LT::clear)
2034  .addFunction ("push_back", (void (LT::*)(const T&))&LT::push_back)
2035  .addExtCFunction ("add", &CFunc::tableToList<T, LT>);
2036  }
2037 
2038  template <class T>
2040  {
2041  typedef T* TP;
2042  typedef std::list<TP> LT;
2043  typedef typename LT::size_type T_SIZE;
2044  return beginClass<LT> (name)
2045  .addVoidConstructor ()
2046  .addFunction ("empty", static_cast<bool (LT::*)() const>(&LT::empty))
2047  .addFunction ("size", static_cast<T_SIZE (LT::*)() const>(&LT::size))
2048  .addFunction ("reverse", static_cast<void (LT::*)()>(&LT::reverse))
2049  .addFunction ("front", static_cast<const TP& (LT::*)() const>(&LT::front))
2050  .addFunction ("back", static_cast<const TP& (LT::*)() const>(&LT::back))
2051  .addExtCFunction ("iter", &CFunc::listIter<T*, LT>)
2052  .addExtCFunction ("table", &CFunc::listToTable<T*, LT>);
2053  }
2054 
2055  template <class T>
2057  {
2058  typedef T* TP;
2059  typedef std::list<TP> LT;
2060  typedef typename LT::size_type T_SIZE;
2061  return beginConstStdCPtrList<T> (name)
2062 #if !defined(_MSC_VER) || (_MSC_VER < 1900)
2063  /* std::list::unique() got broken in later versions of MSVC */
2064 # if (defined(__cplusplus) && __cplusplus >= 201709L)
2065  .addFunction ("unique", (T_SIZE (LT::*)())&LT::unique)
2066 # else
2067  .addFunction ("unique", (void (LT::*)())&LT::unique)
2068 # endif
2069 #endif
2070  .addFunction ("clear", (void (LT::*)())&LT::clear)
2071  .addExtCFunction ("push_back", &CFunc::pushbackptr<T, LT>);
2072  }
2073 
2074 
2075  template <class T>
2077  {
2078  typedef std::vector<T> LT;
2079  typedef typename std::vector<T>::reference T_REF;
2080  typedef typename std::vector<T>::size_type T_SIZE;
2081 
2082  return beginClass<LT> (name)
2083  .addVoidConstructor ()
2084  .addFunction ("empty", (bool (LT::*)()const)&LT::empty)
2085  .addFunction ("size", (T_SIZE (LT::*)()const)&LT::size)
2086  .addFunction ("at", (T_REF (LT::*)(T_SIZE))&LT::at)
2087  .addExtCFunction ("iter", &CFunc::listIter<T, LT>)
2088  .addExtCFunction ("table", &CFunc::listToTable<T, LT>);
2089  }
2090 
2091  template <class T>
2093  {
2094  typedef std::vector<T> LT;
2095  typedef typename std::vector<T>::size_type T_SIZE;
2096  return beginConstStdVector<T> (name)
2097  .addVoidConstructor ()
2098  .addFunction ("push_back", (void (LT::*)(const T&))&LT::push_back)
2099  .addFunction ("clear", (void (LT::*)())&LT::clear)
2100  .addFunction ("reserve", (void (LT::*)(T_SIZE))&LT::reserve)
2101  .addExtCFunction ("to_array", &CFunc::vectorToArray<T, LT>)
2102  .addExtCFunction ("add", &CFunc::tableToList<T, LT>);
2103  }
2104 
2105  //----------------------------------------------------------------------------
2106 
2107  template <class T>
2109  {
2110  typedef std::list<T> const LT;
2111  typedef typename LT::size_type T_SIZE;
2112  return beginClass<std::shared_ptr<LT> > (name)
2113  .addPtrFunction ("empty", (bool (LT::*)()const)&LT::empty)
2114  .addPtrFunction ("size", (T_SIZE (LT::*)()const)&LT::size)
2115  .addPtrFunction ("reverse", (void (LT::*)())&LT::reverse)
2116  .addExtCFunction ("iter", &CFunc::ptrListIter<T, LT>)
2117  .addExtCFunction ("table", &CFunc::ptrListToTable<T, LT>);
2118  }
2119 
2120  template <class T>
2122  {
2123  typedef std::list<T> LT;
2124  typedef typename LT::size_type T_SIZE;
2125  return beginClass<std::shared_ptr<LT> > (name)
2126  //.addVoidPtrConstructor<LT> ()
2127  .addPtrFunction ("empty", (bool (LT::*)()const)&LT::empty)
2128  .addPtrFunction ("size", (T_SIZE (LT::*)()const)&LT::size)
2129  .addPtrFunction ("reverse", (void (LT::*)())&LT::reverse)
2130 #if !defined(_MSC_VER) || (_MSC_VER < 1900)
2131  /* std::list::unique() got broken in later versions of MSVC */
2132 # if (defined(__cplusplus) && __cplusplus >= 201709L)
2133  .addPtrFunction ("unique", (T_SIZE (LT::*)())&LT::unique)
2134 # else
2135  .addPtrFunction ("unique", (void (LT::*)())&LT::unique)
2136 # endif
2137 #endif
2138  .addPtrFunction ("clear", (void (LT::*)())&LT::clear)
2139  .addPtrFunction ("push_back", (void (LT::*)(const T&))&LT::push_back)
2140  .addExtCFunction ("add", &CFunc::ptrTableToList<T, LT>)
2141  .addExtCFunction ("iter", &CFunc::ptrListIter<T, LT>)
2142  .addExtCFunction ("table", &CFunc::ptrListToTable<T, LT>);
2143  }
2144 
2145  template <class T>
2147  {
2148  typedef std::vector<T> const LT;
2149  typedef typename std::vector<T>::reference T_REF;
2150  typedef typename std::vector<T>::size_type T_SIZE;
2151 
2152  return beginClass<std::shared_ptr<LT> > (name)
2153  .addPtrFunction ("empty", (bool (LT::*)()const)&LT::empty)
2154  .addPtrFunction ("size", (T_SIZE (LT::*)()const)&LT::size)
2155  .addPtrFunction ("at", (T_REF (LT::*)(T_SIZE))&LT::at)
2156  .addExtCFunction ("iter", &CFunc::ptrListIter<T, LT>)
2157  .addExtCFunction ("table", &CFunc::ptrListToTable<T, LT>);
2158  }
2159 
2160  template <class T>
2162  {
2163  typedef std::vector<T> LT;
2164  typedef typename std::vector<T>::reference T_REF;
2165  typedef typename std::vector<T>::size_type T_SIZE;
2166 
2167  return beginClass<std::shared_ptr<LT> > (name)
2168  //.addVoidPtrConstructor<LT> ()
2169  .addPtrFunction ("empty", (bool (LT::*)()const)&LT::empty)
2170  .addPtrFunction ("size", (T_SIZE (LT::*)()const)&LT::size)
2171  .addPtrFunction ("clear", (void (LT::*)())&LT::clear)
2172  .addPtrFunction ("push_back", (void (LT::*)(const T&))&LT::push_back)
2173  .addPtrFunction ("at", (T_REF (LT::*)(T_SIZE))&LT::at)
2174  .addExtCFunction ("add", &CFunc::ptrTableToList<T, LT>)
2175  .addExtCFunction ("iter", &CFunc::ptrListIter<T, LT>)
2176  .addExtCFunction ("table", &CFunc::ptrListToTable<T, LT>);
2177  }
2178 
2179  //----------------------------------------------------------------------------
2186  template <class T, class U>
2188  {
2189  CLASSDOC ("[C] Derived Class", _name << name, type_name <T>(), type_name <U>())
2190  return Class <T> (name, this, ClassInfo <U>::getStaticKey ());
2191  }
2192 
2193  template <class T, class U>
2195  {
2196 
2197  CLASSDOC ("[C] Derived Class", _name << name, type_name <std::shared_ptr<T> >(), type_name <std::shared_ptr<U> >())
2198  CLASSDOC ("[C] Derived Class", _name << name, type_name <std::weak_ptr<T> >(), type_name <std::weak_ptr<U> >())
2199  CLASSDOC ("[C] Derived Pointer Class", _name << name, type_name <T>(), type_name <U>())
2200  return WSPtrClass <T> (name, this,
2201  ClassInfo <std::shared_ptr<U> >::getStaticKey (),
2202  ClassInfo <std::shared_ptr<U const> >::getStaticKey (),
2203  ClassInfo <std::weak_ptr<U> >::getStaticKey ())
2204  .addNullCheck()
2205  .addEqualCheck();
2206  }
2207 
2208 };
2209 
2210 //------------------------------------------------------------------------------
2219 {
2220  return Namespace::getGlobalNamespace (L);
2221 }
2222 
2223 
2224 #undef KEYSTA
2225 #undef KEYEND
2226 #undef CLASSDOC
2227 #undef PRINTDOC
2228 #undef FUNDOC
2229 #undef DATADOC
2230 
2231 /* vim: set et sw=2: */
void rawsetfield(lua_State *L, int index, char const *key)
Definition: LuaHelpers.h:116
void rawgetfield(lua_State *L, int index, char const *key)
Definition: LuaHelpers.h:106
#define DATADOC(TYPE, NAME, FUNCTOR)
Definition: Namespace.h:110
#define PRINTDOC(TYPE, LUANAME, RETVAL, DECL)
Definition: Namespace.h:108
#define CLASSDOC(TYPE, LUANAME, DECL, PARENTDECL)
Definition: Namespace.h:107
#define FUNDOC(TYPE, NAME, FUNCTOR)
Definition: Namespace.h:109
Namespace getGlobalNamespace(lua_State *L)
Definition: Namespace.h:2218
void * getIdentityKey()
Definition: Userdata.h:63
Array(char const *name, Namespace const *parent)
Definition: Namespace.h:1167
Namespace endArray()
Definition: Namespace.h:1265
static int ctorPlacementProxy(lua_State *L)
Definition: Namespace.h:470
lua_State *const L
Definition: Namespace.h:192
void createStaticTable(char const *name)
Definition: Namespace.h:418
static int ctorNilPtrPlacementProxy(lua_State *L)
Definition: Namespace.h:487
static int newindexMetaMethod(lua_State *L)
Definition: Namespace.h:303
void createClassTable(char const *name)
Definition: Namespace.h:378
static int indexMetaMethod(lua_State *L)
Definition: Namespace.h:212
static int ctorPtrPlacementProxy(lua_State *L)
Definition: Namespace.h:478
friend class Namespace
Definition: Namespace.h:190
static int ctorContainerProxy(lua_State *L)
Definition: Namespace.h:456
void createConstTable(char const *name)
Definition: Namespace.h:349
ClassBase(lua_State *L_)
Definition: Namespace.h:513
ClassBase(ClassBase const &other)
Definition: Namespace.h:523
ClassBase & operator=(ClassBase const &other)
void pop(int n) const
Definition: Namespace.h:498
Class< T > & addConstructor()
Definition: Namespace.h:1093
Class< T > & addExtCFunction(char const *name, int(*const fp)(lua_State *))
Definition: Namespace.h:1029
Class< T > & addStaticCFunction(char const *name, int(*const fp)(lua_State *))
Definition: Namespace.h:814
Namespace endClass()
Definition: Namespace.h:668
Class< T > & addStaticFunction(char const *name, FP const fp)
Definition: Namespace.h:800
Class< T > & addWPtrFunction(char const *name, MemFn mf)
Definition: Namespace.h:995
Class< T > & addVoidPtrConstructor()
Definition: Namespace.h:1131
Class< T > & addData(char const *name, const U T::*mp, bool isWritable=true)
Definition: Namespace.h:827
Class< T > & addEqualCheck()
Definition: Namespace.h:1136
Class< T > & addCast(char const *name)
Definition: Namespace.h:1145
Class< T > & addStaticData(char const *name, U *pu, bool isWritable=true)
Definition: Namespace.h:678
Class(char const *name, Namespace const *parent)
Definition: Namespace.h:563
Class< T > & addPtrConstructor()
Definition: Namespace.h:1115
Class< T > & addFunction(char const *name, MemFn mf)
Definition: Namespace.h:979
Class< T > & addCFunction(char const *name, int(T::*mfp)(lua_State *) const)
Definition: Namespace.h:1044
Class< T > & addRefFunction(char const *name, MemFn mf)
Definition: Namespace.h:1003
Class< T > & addMetamethod(char const *name, FP const fp)
Definition: Namespace.h:775
Class< T > & addConstructor()
Definition: Namespace.h:1104
Class(char const *name, Namespace const *parent, void const *const staticKey)
Definition: Namespace.h:619
Class< T > & addVoidConstructor()
Definition: Namespace.h:1125
Class< T > & addProperty(char const *name, TG(T::*get)() const, bool(T::*set)(TS))
Definition: Namespace.h:863
Class< T > & addProperty(char const *name, TG(*get)(T const *), bool(*set)(T *, TS))
Definition: Namespace.h:925
Class< T > & addOperator(char const *name, int(*const fp)(lua_State *))
Definition: Namespace.h:752
Class< T > & addConst(char const *name, const U val)
Definition: Namespace.h:1062
Class< T > & addPtrFunction(char const *name, MemFn mf)
Definition: Namespace.h:987
Class< T > & addCFunction(char const *name, int(T::*mfp)(lua_State *))
Definition: Namespace.h:1015
WSPtrClass< T > & addNullCheck()
Definition: Namespace.h:1459
Class< std::weak_ptr< T > > weak
Definition: Namespace.h:1607
Class< std::shared_ptr< T const > > shared_const
Definition: Namespace.h:1606
WSPtrClass< T > & addNilPtrConstructor()
Definition: Namespace.h:1388
WSPtrClass< T > & addEqualCheck()
Definition: Namespace.h:1480
WSPtrClass< T > & addStaticFunction(char const *name, FP const fp)
Definition: Namespace.h:1368
WSPtrClass(char const *name, Namespace const *parent, void const *const sharedkey, void const *const sharedconstkey, void const *const weakkey)
Definition: Namespace.h:1294
Class< std::shared_ptr< T > > shared
Definition: Namespace.h:1605
WSPtrClass< T > & addCast(char const *name)
Definition: Namespace.h:1439
WSPtrClass(char const *name, Namespace const *parent)
Definition: Namespace.h:1276
WSPtrClass< T > & addData(char const *name, const U T::*mp, bool isWritable=true)
Definition: Namespace.h:1501
WSPtrClass< T > & addFunction(char const *name, MemFn mf)
Definition: Namespace.h:1310
WSPtrClass< T > & addRefFunction(char const *name, MemFn mf)
Definition: Namespace.h:1325
Namespace endClass()
Definition: Namespace.h:1574
void set_const_shared_class()
Definition: Namespace.h:1596
WSPtrClass< T > & addExtCFunction(char const *name, int(*const fp)(lua_State *))
Definition: Namespace.h:1411
WSPtrClass< T > & addConstructor()
Definition: Namespace.h:1340
WSPtrClass< T > & addVoidConstructor()
Definition: Namespace.h:1362
Namespace(ClassBase const *child)
Definition: Namespace.h:1709
Class< std::set< T > > beginStdSet(char const *name)
Definition: Namespace.h:1970
Class< T > beginClass(char const *name)
Definition: Namespace.h:1933
Namespace & addCFunction(char const *name, int(*const fp)(lua_State *))
Definition: Namespace.h:1919
Class< T > deriveClass(char const *name)
Definition: Namespace.h:2187
int m_stackSize
Definition: Namespace.h:125
WSPtrClass< T > beginWSPtrClass(char const *name)
Definition: Namespace.h:1940
Class< std::shared_ptr< std::list< T > > > beginPtrStdList(char const *name)
Definition: Namespace.h:2121
Namespace beginNamespace(char const *name)
Definition: Namespace.h:1763
Class< std::shared_ptr< std::vector< T > > > beginPtrStdVector(char const *name)
Definition: Namespace.h:2161
Namespace & addRefFunction(char const *name, FP const fp)
Definition: Namespace.h:1891
Namespace & addFunction(char const *name, FP const fp)
Definition: Namespace.h:1878
Namespace registerArray(char const *name)
Definition: Namespace.h:1909
Class< std::map< K, V > > beginStdMap(char const *name)
Definition: Namespace.h:1950
Namespace(char const *name, Namespace const *parent)
Definition: Namespace.h:1640
Namespace(lua_State *L_)
Definition: Namespace.h:1616
WSPtrClass< T > deriveWSPtrClass(char const *name)
Definition: Namespace.h:2194
Namespace & addVariable(char const *name, T *pt, bool isWritable=true)
Definition: Namespace.h:1784
Class< std::bitset< T > > beginStdBitSet(char const *name)
Definition: Namespace.h:1987
static Namespace getGlobalNamespace(lua_State *L)
Definition: Namespace.h:1754
Class< std::shared_ptr< const std::vector< T > > > beginPtrConstStdVector(char const *name)
Definition: Namespace.h:2146
Class< std::vector< T > > beginStdVector(char const *name)
Definition: Namespace.h:2092
Namespace(Namespace const &other)
Definition: Namespace.h:1731
Namespace & operator=(Namespace const &other)
Namespace endNamespace()
Definition: Namespace.h:1774
void pop(int n) const
Definition: Namespace.h:167
Namespace & addConst(char const *name, const U val)
Definition: Namespace.h:1814
lua_State *const L
Definition: Namespace.h:124
Class< std::list< T > > beginStdList(char const *name)
Definition: Namespace.h:2020
Class< std::list< T > > beginConstStdList(char const *name)
Definition: Namespace.h:2004
Namespace(Namespace const *child)
Definition: Namespace.h:1687
Class< std::list< T * > > beginConstStdCPtrList(char const *name)
Definition: Namespace.h:2039
Class< std::list< T * > > beginStdCPtrList(char const *name)
Definition: Namespace.h:2056
Class< std::vector< T > > beginConstStdVector(char const *name)
Definition: Namespace.h:2076
Class< std::shared_ptr< const std::list< T > > > beginPtrConstStdList(char const *name)
Definition: Namespace.h:2108
GtkImageIconNameData name
Definition: gtkimage.h:6
int() luaL_error(lua_State *L, const char *fmt,...)
int() luaL_newmetatable(lua_State *L, const char *tname)
int() lua_getinfo(lua_State *L, const char *what, lua_Debug *ar)
#define lua_istable(L, n)
#define lua_insert(L, idx)
int() lua_rawget(lua_State *L, int idx)
#define lua_pushcfunction(L, f)
int() lua_rawgetp(lua_State *L, int idx, const void *p)
Definition: LuaHelpers.h:41
void() lua_setfield(lua_State *L, int idx, const char *k)
#define LUA_REGISTRYINDEX
Definition: lua-5.3.5/lua.h:42
int() lua_iscfunction(lua_State *L, int idx)
void() lua_pushvalue(lua_State *L, int idx)
void() lua_pushlightuserdata(lua_State *L, void *p)
int() lua_setmetatable(lua_State *L, int objindex)
const char *() lua_pushstring(lua_State *L, const char *s)
void *() lua_newuserdata(lua_State *L, size_t sz)
void() lua_rawsetp(lua_State *L, int idx, const void *p)
Definition: LuaHelpers.h:48
#define lua_isfunction(L, n)
#define lua_remove(L, idx)
#define lua_isnil(L, n)
#define lua_call(L, n, r)
#define lua_newtable(L)
void() lua_pushboolean(lua_State *L, int b)
int() lua_gettop(lua_State *L)
void() lua_pushnumber(lua_State *L, lua_Number n)
int() lua_isstring(lua_State *L, int idx)
void() lua_pushnil(lua_State *L)
#define lua_pop(L, n)
#define lua_upvalueindex(i)
Definition: lua-5.3.5/lua.h:43
int() lua_getmetatable(lua_State *L, int objindex)
int() lua_getstack(lua_State *L, int level, lua_Debug *ar)
int() lua_isuserdata(lua_State *L, int idx)
#define lua_tostring(L, i)
int() lua_getglobal(lua_State *L, const char *name)
void() lua_pushcclosure(lua_State *L, lua_CFunction fn, int n)
void add(const Gtk::StockItem &item)
static int newindexMetaMethod(lua_State *L)
Definition: CFunctions.h:107
static int readOnlyError(lua_State *L)
Definition: CFunctions.h:155
static int indexMetaMethod(lua_State *L)
Definition: CFunctions.h:43
static void push(lua_State *L, T const &t)
Definition: Userdata.h:646
char short_src[60]