Permalink
Browse files

Initial supporte to extension SLB: http://code.google.com/p/slb/

  • Loading branch information...
1 parent 8307cb5 commit 436b1f066a9e303da0110691e6739cf7a4aae655 @nuxlli committed Nov 29, 2010
Showing with 7,436 additions and 0 deletions.
  1. +437 −0 lib/extensions/SLB/Headers/SLB/Class.hpp
  2. +50 −0 lib/extensions/SLB/Headers/SLB/ClassHelpers.hpp
  3. +170 −0 lib/extensions/SLB/Headers/SLB/ClassInfo.hpp
  4. +63 −0 lib/extensions/SLB/Headers/SLB/Conversor.hpp
  5. +164 −0 lib/extensions/SLB/Headers/SLB/Debug.hpp
  6. +144 −0 lib/extensions/SLB/Headers/SLB/Error.hpp
  7. +47 −0 lib/extensions/SLB/Headers/SLB/Export.hpp
  8. +149 −0 lib/extensions/SLB/Headers/SLB/FuncCall.hpp
  9. +278 −0 lib/extensions/SLB/Headers/SLB/Hybrid.hpp
  10. +357 −0 lib/extensions/SLB/Headers/SLB/Instance.hpp
  11. +147 −0 lib/extensions/SLB/Headers/SLB/Iterator.hpp
  12. +124 −0 lib/extensions/SLB/Headers/SLB/LuaCall.hpp
  13. +215 −0 lib/extensions/SLB/Headers/SLB/Manager.hpp
  14. +151 −0 lib/extensions/SLB/Headers/SLB/Mutex.hpp
  15. +91 −0 lib/extensions/SLB/Headers/SLB/Object.hpp
  16. +219 −0 lib/extensions/SLB/Headers/SLB/Private_FuncCall.hpp
  17. +102 −0 lib/extensions/SLB/Headers/SLB/PushGet.hpp
  18. +53 −0 lib/extensions/SLB/Headers/SLB/SLB.hpp
  19. +248 −0 lib/extensions/SLB/Headers/SLB/SPP.hpp
  20. +94 −0 lib/extensions/SLB/Headers/SLB/Script.hpp
  21. +68 −0 lib/extensions/SLB/Headers/SLB/StatefulHybrid.hpp
  22. +111 −0 lib/extensions/SLB/Headers/SLB/Table.hpp
  23. +744 −0 lib/extensions/SLB/Headers/SLB/Type.hpp
  24. +88 −0 lib/extensions/SLB/Headers/SLB/TypeInfoWrapper.hpp
  25. +180 −0 lib/extensions/SLB/Headers/SLB/Value.hpp
  26. +43 −0 lib/extensions/SLB/Headers/SLB/lua.hpp
  27. +94 −0 lib/extensions/SLB/Headers/SLB/ref_ptr.hpp
  28. +37 −0 lib/extensions/SLB/Headers/SLB/util.hpp
  29. +29 −0 lib/extensions/SLB/Sources/Class.cpp
  30. +29 −0 lib/extensions/SLB/Sources/ClassHelpers.cpp
  31. +467 −0 lib/extensions/SLB/Sources/ClassInfo.cpp
  32. +31 −0 lib/extensions/SLB/Sources/Debug.cpp
  33. +181 −0 lib/extensions/SLB/Sources/Error.cpp
  34. +107 −0 lib/extensions/SLB/Sources/FuncCall.cpp
  35. +395 −0 lib/extensions/SLB/Sources/Hybrid.cpp
  36. +44 −0 lib/extensions/SLB/Sources/Instance.cpp
  37. +57 −0 lib/extensions/SLB/Sources/Iterator.cpp
  38. +113 −0 lib/extensions/SLB/Sources/LuaCall.cpp
  39. +437 −0 lib/extensions/SLB/Sources/Manager.cpp
  40. +164 −0 lib/extensions/SLB/Sources/Object.cpp
  41. +28 −0 lib/extensions/SLB/Sources/SLB.cpp
  42. +160 −0 lib/extensions/SLB/Sources/Script.cpp
  43. +316 −0 lib/extensions/SLB/Sources/Table.cpp
  44. +29 −0 lib/extensions/SLB/Sources/Type.cpp
  45. +29 −0 lib/extensions/SLB/Sources/Value.cpp
  46. +19 −0 lib/extensions/SLB/WaxScript.cpp
  47. +20 −0 lib/extensions/SLB/WaxScript.h
  48. +19 −0 lib/extensions/SLB/slb_wax.h
  49. +14 −0 lib/extensions/SLB/slb_wax.mm
  50. +32 −0 lib/extensions/SLB/wax_slb.h
  51. +48 −0 lib/extensions/SLB/wax_slb.mm
Oops, something went wrong.
@@ -0,0 +1,50 @@
+/*
+ SLB - Simple Lua Binder
+ Copyright (C) 2007-2010 Jose L. Hidalgo Valiño (PpluX)
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+
+ Jose L. Hidalgo (www.pplux.com)
+ pplux@pplux.com
+*/
+
+
+#ifndef __SLB_CLASS_HELPERS__
+#define __SLB_CLASS_HELPERS__
+
+#include "SPP.hpp"
+#include "FuncCall.hpp"
+
+struct lua_State;
+
+namespace SLB {
+
+ template<class C>
+ struct Operator
+ {
+ static C* defaultAdd (const C *a, const C *b) { return new C( (*a)+(*b) ); }
+ static C* defaultSub (const C *a, const C *b) { return new C( (*a)-(*b) ); }
+ static C* defaultMult(const C *a, const C *b) { return new C( (*a)*(*b) ); }
+ static C* defaultDiv (const C *a, const C *b) { return new C( (*a)/(*b) ); }
+ };
+
+}
+
+
+#endif
@@ -0,0 +1,170 @@
+/*
+ SLB - Simple Lua Binder
+ Copyright (C) 2007-2010 Jose L. Hidalgo Valiño (PpluX)
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+
+ Jose L. Hidalgo (www.pplux.com)
+ pplux@pplux.com
+*/
+
+
+
+#ifndef __SLB_CLASS_INFO__
+#define __SLB_CLASS_INFO__
+
+#include "Export.hpp"
+#include "Object.hpp"
+#include "Instance.hpp"
+#include "Table.hpp"
+#include "ref_ptr.hpp"
+#include "FuncCall.hpp"
+//#include "ClassHelpers.hpp"
+#include <typeinfo>
+#include <map>
+#include <vector>
+#include <string>
+
+struct lua_State;
+
+namespace SLB {
+
+ class SLB_EXPORT Namespace : public Table
+ {
+ public:
+ Namespace( bool cacheable = true ) : Table("::", cacheable) {}
+ protected:
+ virtual ~Namespace() {}
+ };
+
+ class SLB_EXPORT ClassInfo : public Namespace
+ {
+ public:
+ typedef std::map<TypeInfoWrapper, ref_ptr<ClassInfo> > BaseClassMap;
+
+ const TypeInfoWrapper &getTypeid() const { return _typeid; }
+ const std::string &getName() const { return _name; }
+ void setName(const std::string&);
+
+ void push_ref(lua_State *L, void *ref);
+ void push_ptr(lua_State *L, void *ptr, bool fromConstructor = false);
+ void push_const_ptr(lua_State *L, const void *const_ptr);
+ void push_copy(lua_State *L, const void *ptr);
+ void* get_ptr(lua_State*, int pos) const;
+ const void* get_const_ptr(lua_State*, int pos) const;
+
+ // Uses dynamic_cast to convert from Base to Derived
+ template<class This, class Base>
+ void inheritsFrom();
+
+ // This version uses static cast instead of dynamic_cast
+ template<class This, class Base>
+ void staticInheritsFrom();
+
+
+ void setConstructor( FuncCall *constructor );
+ void setInstanceFactory( InstanceFactory *);
+
+ /** __index method will receive:
+ * - object
+ * - key */
+ void setObject__index( FuncCall* );
+
+ /** __index method will receive:
+ * - object
+ * - key
+ * - value */
+ void setObject__newindex( FuncCall* );
+
+ /** Here you can use setCache/getCache methods to
+ * speed up indexing.
+ *
+ * __index method will receive:
+ * - [table] -> ClassInfo
+ * - key */
+ void setClass__index( FuncCall* );
+
+ /** Here you can use setCache/getCache methods to
+ * speed up indexing.
+ * __index method will receive:
+ * - [table] -> ClassInfo
+ * - key
+ * - value */
+ void setClass__newindex( FuncCall* );
+
+ //This is used by some default initializations...
+ bool initialized() const { return _instanceFactory != 0; }
+
+ bool isSubClassOf( const ClassInfo* );
+ bool hasConstructor() const { return _constructor.valid(); }
+
+ //--Private methods -(not meant to be used)-------------------
+ void setHybrid() { _isHybrid = true; }
+ FuncCall* getConstructor() { return _constructor.get(); }
+
+ protected:
+ ClassInfo(const TypeInfoWrapper &);
+ virtual ~ClassInfo();
+ void pushImplementation(lua_State *);
+ virtual int __index(lua_State*);
+ virtual int __newindex(lua_State*);
+ virtual int __call(lua_State*);
+ virtual int __garbageCollector(lua_State*);
+ virtual int __tostring(lua_State*);
+
+ TypeInfoWrapper _typeid;
+ std::string _name;
+ InstanceFactory *_instanceFactory;
+ BaseClassMap _baseClasses;
+ ref_ptr<FuncCall> _constructor;
+ ref_ptr<FuncCall> _meta__index[2]; // 0 = class, 1 = object
+ ref_ptr<FuncCall> _meta__newindex[2]; // 0 = class, 1 = object
+ bool _isHybrid;
+
+ private:
+ void pushInstance(lua_State *L, InstanceBase *instance);
+ InstanceBase* getInstance(lua_State *L, int pos) const;
+
+ friend class Manager;
+ };
+
+
+ //--------------------------------------------------------------------
+ // Inline implementations:
+ //--------------------------------------------------------------------
+
+
+ template<class D, class B>
+ inline void ClassInfo::inheritsFrom()
+ {
+ Manager::getInstance().template addConversor<D,B>();
+ _baseClasses[ _TIW(B) ] = Manager::getInstance().getOrCreateClass(_TIW(B));
+ }
+
+ template<class D, class B>
+ inline void ClassInfo::staticInheritsFrom()
+ {
+ Manager::getInstance().template addStaticConversor<D,B>();
+ _baseClasses[ _TIW(B) ] = Manager::getInstance().getOrCreateClass(_TIW(B));
+ }
+
+}
+
+
+#endif
@@ -0,0 +1,63 @@
+/*
+ SLB - Simple Lua Binder
+ Copyright (C) 2007-2010 Jose L. Hidalgo Valiño (PpluX)
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+
+ Jose L. Hidalgo (www.pplux.com)
+ pplux@pplux.com
+*/
+
+
+
+#ifndef __SLB_CONVERSOR__
+#define __SLB_CONVERSOR__
+
+namespace SLB {
+
+ struct Conversor
+ {
+ virtual void* operator()(void* obj) = 0;
+ virtual ~Conversor() {}
+ };
+
+ template<class B, class D>
+ struct BaseToDerived : public Conversor
+ {
+ void *operator()(void* obj_raw)
+ {
+ B *obj = reinterpret_cast<B*>(obj_raw);
+ return dynamic_cast<D*>(obj);
+ }
+ };
+
+ template<class D, class B>
+ struct DerivedToBase : public Conversor
+ {
+ void *operator()(void* obj_raw)
+ {
+ D *obj = reinterpret_cast<D*>(obj_raw);
+ B *base_obj = obj; // D -> B
+ return base_obj;
+ }
+ };
+
+}
+
+#endif
Oops, something went wrong.

0 comments on commit 436b1f0

Please sign in to comment.