mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-16 18:52:22 +00:00
Lua work - loading works, I think checking for sub works. Calling subs is in the beginning stages and binding is starting
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,348 @@
|
||||
//==============================================================================
|
||||
/*
|
||||
https://github.com/vinniefalco/LuaBridge
|
||||
https://github.com/vinniefalco/LuaBridgeDemo
|
||||
|
||||
Copyright (C) 2012, Vinnie Falco <vinnie.falco@gmail.com>
|
||||
Copyright 2004-11 by Raw Material Software Ltd.
|
||||
|
||||
This is a derivative work used by permission from part of
|
||||
JUCE, available at http://www.rawaterialsoftware.com
|
||||
|
||||
License: The MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
|
||||
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.
|
||||
|
||||
This file incorporates work covered by the following copyright and
|
||||
permission notice:
|
||||
|
||||
This file is part of the JUCE library - "Jules' Utility Class Extensions"
|
||||
Copyright 2004-11 by Raw Material Software Ltd.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#ifndef LUABRIDGE_REFCOUNTEDOBJECT_HEADER
|
||||
#define LUABRIDGE_REFCOUNTEDOBJECT_HEADER
|
||||
|
||||
#if !defined (LUABRIDGE_LUABRIDGE_HEADER)
|
||||
#error LuaBridge.h must be included before including this file
|
||||
#endif
|
||||
|
||||
//#define LUABRIDGE_COMPILER_SUPPORTS_MOVE_SEMANTICS 1
|
||||
|
||||
//==============================================================================
|
||||
/**
|
||||
Adds reference-counting to an object.
|
||||
|
||||
To add reference-counting to a class, derive it from this class, and
|
||||
use the RefCountedObjectPtr class to point to it.
|
||||
|
||||
e.g. @code
|
||||
class MyClass : public RefCountedObjectType
|
||||
{
|
||||
void foo();
|
||||
|
||||
// This is a neat way of declaring a typedef for a pointer class,
|
||||
// rather than typing out the full templated name each time..
|
||||
typedef RefCountedObjectPtr<MyClass> Ptr;
|
||||
};
|
||||
|
||||
MyClass::Ptr p = new MyClass();
|
||||
MyClass::Ptr p2 = p;
|
||||
p = 0;
|
||||
p2->foo();
|
||||
@endcode
|
||||
|
||||
Once a new RefCountedObjectType has been assigned to a pointer, be
|
||||
careful not to delete the object manually.
|
||||
*/
|
||||
template <class CounterType>
|
||||
class RefCountedObjectType
|
||||
{
|
||||
public:
|
||||
//==============================================================================
|
||||
/** Increments the object's reference count.
|
||||
|
||||
This is done automatically by the smart pointer, but is public just
|
||||
in case it's needed for nefarious purposes.
|
||||
*/
|
||||
inline void incReferenceCount() const
|
||||
{
|
||||
++refCount;
|
||||
}
|
||||
|
||||
/** Decreases the object's reference count.
|
||||
|
||||
If the count gets to zero, the object will be deleted.
|
||||
*/
|
||||
inline void decReferenceCount() const
|
||||
{
|
||||
assert (getReferenceCount() > 0);
|
||||
|
||||
if (--refCount == 0)
|
||||
delete this;
|
||||
}
|
||||
|
||||
/** Returns the object's current reference count. */
|
||||
inline int getReferenceCount() const
|
||||
{
|
||||
return static_cast <int> (refCount);
|
||||
}
|
||||
|
||||
protected:
|
||||
//==============================================================================
|
||||
/** Creates the reference-counted object (with an initial ref count of zero). */
|
||||
RefCountedObjectType() : refCount ()
|
||||
{
|
||||
}
|
||||
|
||||
/** Destructor. */
|
||||
virtual ~RefCountedObjectType()
|
||||
{
|
||||
// it's dangerous to delete an object that's still referenced by something else!
|
||||
assert (getReferenceCount() == 0);
|
||||
}
|
||||
|
||||
private:
|
||||
//==============================================================================
|
||||
CounterType mutable refCount;
|
||||
};
|
||||
|
||||
//==============================================================================
|
||||
/**
|
||||
A smart-pointer class which points to a reference-counted object.
|
||||
|
||||
The template parameter specifies the class of the object you want to point to - the easiest
|
||||
way to make a class reference-countable is to simply make it inherit from RefCountedObjectType,
|
||||
but if you need to, you could roll your own reference-countable class by implementing a pair of
|
||||
mathods called incReferenceCount() and decReferenceCount().
|
||||
|
||||
When using this class, you'll probably want to create a typedef to abbreviate the full
|
||||
templated name - e.g.
|
||||
|
||||
@code typedef RefCountedObjectPtr <MyClass> MyClassPtr;@endcode
|
||||
*/
|
||||
template <class ReferenceCountedObjectClass>
|
||||
class RefCountedObjectPtr
|
||||
{
|
||||
public:
|
||||
/** The class being referenced by this pointer. */
|
||||
typedef ReferenceCountedObjectClass ReferencedType;
|
||||
|
||||
//==============================================================================
|
||||
/** Creates a pointer to a null object. */
|
||||
inline RefCountedObjectPtr() : referencedObject (0)
|
||||
{
|
||||
}
|
||||
|
||||
/** Creates a pointer to an object.
|
||||
|
||||
This will increment the object's reference-count if it is non-null.
|
||||
*/
|
||||
inline RefCountedObjectPtr (ReferenceCountedObjectClass* const refCountedObject)
|
||||
: referencedObject (refCountedObject)
|
||||
{
|
||||
if (refCountedObject != 0)
|
||||
refCountedObject->incReferenceCount();
|
||||
}
|
||||
|
||||
/** Copies another pointer.
|
||||
This will increment the object's reference-count (if it is non-null).
|
||||
*/
|
||||
inline RefCountedObjectPtr (const RefCountedObjectPtr& other)
|
||||
: referencedObject (other.referencedObject)
|
||||
{
|
||||
if (referencedObject != 0)
|
||||
referencedObject->incReferenceCount();
|
||||
}
|
||||
|
||||
#if LUABRIDGE_COMPILER_SUPPORTS_MOVE_SEMANTICS
|
||||
/** Takes-over the object from another pointer. */
|
||||
inline RefCountedObjectPtr (RefCountedObjectPtr&& other)
|
||||
: referencedObject (other.referencedObject)
|
||||
{
|
||||
other.referencedObject = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/** Copies another pointer.
|
||||
This will increment the object's reference-count (if it is non-null).
|
||||
*/
|
||||
template <class DerivedClass>
|
||||
inline RefCountedObjectPtr (const RefCountedObjectPtr<DerivedClass>& other)
|
||||
: referencedObject (static_cast <ReferenceCountedObjectClass*> (other.getObject()))
|
||||
{
|
||||
if (referencedObject != 0)
|
||||
referencedObject->incReferenceCount();
|
||||
}
|
||||
|
||||
/** Changes this pointer to point at a different object.
|
||||
|
||||
The reference count of the old object is decremented, and it might be
|
||||
deleted if it hits zero. The new object's count is incremented.
|
||||
*/
|
||||
RefCountedObjectPtr& operator= (const RefCountedObjectPtr& other)
|
||||
{
|
||||
return operator= (other.referencedObject);
|
||||
}
|
||||
|
||||
/** Changes this pointer to point at a different object.
|
||||
|
||||
The reference count of the old object is decremented, and it might be
|
||||
deleted if it hits zero. The new object's count is incremented.
|
||||
*/
|
||||
template <class DerivedClass>
|
||||
RefCountedObjectPtr& operator= (const RefCountedObjectPtr<DerivedClass>& other)
|
||||
{
|
||||
return operator= (static_cast <ReferenceCountedObjectClass*> (other.getObject()));
|
||||
}
|
||||
|
||||
#if LUABRIDGE_COMPILER_SUPPORTS_MOVE_SEMANTICS
|
||||
/** Takes-over the object from another pointer. */
|
||||
RefCountedObjectPtr& operator= (RefCountedObjectPtr&& other)
|
||||
{
|
||||
std::swap (referencedObject, other.referencedObject);
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
|
||||
/** Changes this pointer to point at a different object.
|
||||
|
||||
The reference count of the old object is decremented, and it might be
|
||||
deleted if it hits zero. The new object's count is incremented.
|
||||
*/
|
||||
RefCountedObjectPtr& operator= (ReferenceCountedObjectClass* const newObject)
|
||||
{
|
||||
if (referencedObject != newObject)
|
||||
{
|
||||
if (newObject != 0)
|
||||
newObject->incReferenceCount();
|
||||
|
||||
ReferenceCountedObjectClass* const oldObject = referencedObject;
|
||||
referencedObject = newObject;
|
||||
|
||||
if (oldObject != 0)
|
||||
oldObject->decReferenceCount();
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/** Destructor.
|
||||
|
||||
This will decrement the object's reference-count, and may delete it if it
|
||||
gets to zero.
|
||||
*/
|
||||
inline ~RefCountedObjectPtr()
|
||||
{
|
||||
if (referencedObject != 0)
|
||||
referencedObject->decReferenceCount();
|
||||
}
|
||||
|
||||
/** Returns the object that this pointer references.
|
||||
The pointer returned may be zero, of course.
|
||||
*/
|
||||
inline operator ReferenceCountedObjectClass*() const
|
||||
{
|
||||
return referencedObject;
|
||||
}
|
||||
|
||||
// the -> operator is called on the referenced object
|
||||
inline ReferenceCountedObjectClass* operator->() const
|
||||
{
|
||||
return referencedObject;
|
||||
}
|
||||
|
||||
/** Returns the object that this pointer references.
|
||||
The pointer returned may be zero, of course.
|
||||
*/
|
||||
inline ReferenceCountedObjectClass* getObject() const
|
||||
{
|
||||
return referencedObject;
|
||||
}
|
||||
|
||||
private:
|
||||
//==============================================================================
|
||||
ReferenceCountedObjectClass* referencedObject;
|
||||
};
|
||||
|
||||
/** Compares two ReferenceCountedObjectPointers. */
|
||||
template <class ReferenceCountedObjectClass>
|
||||
bool operator== (const RefCountedObjectPtr<ReferenceCountedObjectClass>& object1, ReferenceCountedObjectClass* const object2)
|
||||
{
|
||||
return object1.getObject() == object2;
|
||||
}
|
||||
|
||||
/** Compares two ReferenceCountedObjectPointers. */
|
||||
template <class ReferenceCountedObjectClass>
|
||||
bool operator== (const RefCountedObjectPtr<ReferenceCountedObjectClass>& object1, const RefCountedObjectPtr<ReferenceCountedObjectClass>& object2)
|
||||
{
|
||||
return object1.getObject() == object2.getObject();
|
||||
}
|
||||
|
||||
/** Compares two ReferenceCountedObjectPointers. */
|
||||
template <class ReferenceCountedObjectClass>
|
||||
bool operator== (ReferenceCountedObjectClass* object1, RefCountedObjectPtr<ReferenceCountedObjectClass>& object2)
|
||||
{
|
||||
return object1 == object2.getObject();
|
||||
}
|
||||
|
||||
/** Compares two ReferenceCountedObjectPointers. */
|
||||
template <class ReferenceCountedObjectClass>
|
||||
bool operator!= (const RefCountedObjectPtr<ReferenceCountedObjectClass>& object1, const ReferenceCountedObjectClass* object2)
|
||||
{
|
||||
return object1.getObject() != object2;
|
||||
}
|
||||
|
||||
/** Compares two ReferenceCountedObjectPointers. */
|
||||
template <class ReferenceCountedObjectClass>
|
||||
bool operator!= (const RefCountedObjectPtr<ReferenceCountedObjectClass>& object1, RefCountedObjectPtr<ReferenceCountedObjectClass>& object2)
|
||||
{
|
||||
return object1.getObject() != object2.getObject();
|
||||
}
|
||||
|
||||
/** Compares two ReferenceCountedObjectPointers. */
|
||||
template <class ReferenceCountedObjectClass>
|
||||
bool operator!= (ReferenceCountedObjectClass* object1, RefCountedObjectPtr<ReferenceCountedObjectClass>& object2)
|
||||
{
|
||||
return object1 != object2.getObject();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
||||
namespace luabridge
|
||||
{
|
||||
|
||||
template <class T>
|
||||
struct ContainerTraits <RefCountedObjectPtr <T> >
|
||||
{
|
||||
typedef T Type;
|
||||
|
||||
static T* get (RefCountedObjectPtr <T> const& c)
|
||||
{
|
||||
return c.getObject ();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,248 @@
|
||||
//==============================================================================
|
||||
/*
|
||||
https://github.com/vinniefalco/LuaBridge
|
||||
https://github.com/vinniefalco/LuaBridgeDemo
|
||||
|
||||
Copyright (C) 2012, Vinnie Falco <vinnie.falco@gmail.com>
|
||||
Copyright (C) 2007, Nathan Reed
|
||||
|
||||
License: The MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
|
||||
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.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#ifndef LUABRIDGE_REFCOUNTEDPTR_HEADER
|
||||
#define LUABRIDGE_REFCOUNTEDPTR_HEADER
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# include <hash_map>
|
||||
#else
|
||||
# include <stdint.h>
|
||||
# include <ext/hash_map>
|
||||
#endif
|
||||
|
||||
//==============================================================================
|
||||
/**
|
||||
Support for our RefCountedPtr.
|
||||
*/
|
||||
struct RefCountedPtrBase
|
||||
{
|
||||
// Declaration of container for the refcounts
|
||||
#ifdef _MSC_VER
|
||||
typedef stdext::hash_map <const void *, int> RefCountsType;
|
||||
#else
|
||||
struct ptr_hash
|
||||
{
|
||||
size_t operator () (const void * const v) const
|
||||
{
|
||||
static __gnu_cxx::hash<unsigned int> H;
|
||||
return H(uintptr_t(v));
|
||||
}
|
||||
};
|
||||
typedef __gnu_cxx::hash_map<const void *, int, ptr_hash> RefCountsType;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
inline RefCountsType& getRefCounts ()
|
||||
{
|
||||
static RefCountsType refcounts;
|
||||
return refcounts ;
|
||||
}
|
||||
};
|
||||
|
||||
//==============================================================================
|
||||
/**
|
||||
A reference counted smart pointer.
|
||||
|
||||
The api is compatible with boost::RefCountedPtr and std::RefCountedPtr, in the
|
||||
sense that it implements a strict subset of the functionality.
|
||||
|
||||
This implementation uses a hash table to look up the reference count
|
||||
associated with a particular pointer.
|
||||
|
||||
@tparam T The class type.
|
||||
|
||||
@todo Decompose RefCountedPtr using a policy. At a minimum, the underlying
|
||||
reference count should be policy based (to support atomic operations)
|
||||
and the delete behavior should be policy based (to support custom
|
||||
disposal methods).
|
||||
|
||||
@todo Provide an intrusive version of RefCountedPtr.
|
||||
*/
|
||||
template <class T>
|
||||
class RefCountedPtr : private RefCountedPtrBase
|
||||
{
|
||||
public:
|
||||
template <typename Other>
|
||||
struct rebind
|
||||
{
|
||||
typedef RefCountedPtr <Other> other;
|
||||
};
|
||||
|
||||
/** Construct as nullptr or from existing pointer to T.
|
||||
|
||||
@param p The optional, existing pointer to assign from.
|
||||
*/
|
||||
RefCountedPtr (T* p = 0) : m_p (p)
|
||||
{
|
||||
++getRefCounts () [m_p];
|
||||
}
|
||||
|
||||
/** Construct from another RefCountedPtr.
|
||||
|
||||
@param rhs The RefCountedPtr to assign from.
|
||||
*/
|
||||
RefCountedPtr (RefCountedPtr <T> const& rhs) : m_p (rhs.get())
|
||||
{
|
||||
++getRefCounts () [m_p];
|
||||
}
|
||||
|
||||
/** Construct from a RefCountedPtr of a different type.
|
||||
|
||||
@invariant A pointer to U must be convertible to a pointer to T.
|
||||
|
||||
@param rhs The RefCountedPtr to assign from.
|
||||
@tparam U The other object type.
|
||||
*/
|
||||
template <typename U>
|
||||
RefCountedPtr (RefCountedPtr <U> const& rhs) : m_p (static_cast <T*> (rhs.get()))
|
||||
{
|
||||
++getRefCounts () [m_p];
|
||||
}
|
||||
|
||||
/** Release the object.
|
||||
|
||||
If there are no more references then the object is deleted.
|
||||
*/
|
||||
~RefCountedPtr ()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
/** Assign from another RefCountedPtr.
|
||||
|
||||
@param rhs The RefCountedPtr to assign from.
|
||||
@return A reference to the RefCountedPtr.
|
||||
*/
|
||||
RefCountedPtr <T>& operator= (RefCountedPtr <T> const& rhs)
|
||||
{
|
||||
if (m_p != rhs.m_p)
|
||||
{
|
||||
reset ();
|
||||
m_p = rhs.m_p;
|
||||
++getRefCounts () [m_p];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
/** Assign from another RefCountedPtr of a different type.
|
||||
|
||||
@note A pointer to U must be convertible to a pointer to T.
|
||||
|
||||
@tparam U The other object type.
|
||||
@param rhs The other RefCountedPtr to assign from.
|
||||
@return A reference to the RefCountedPtr.
|
||||
*/
|
||||
template <typename U>
|
||||
RefCountedPtr <T>& operator= (RefCountedPtr <U> const& rhs)
|
||||
{
|
||||
reset ();
|
||||
m_p = static_cast <T*> (rhs.get());
|
||||
++getRefCounts () [m_p];
|
||||
return *this;
|
||||
}
|
||||
|
||||
/** Retrieve the raw pointer.
|
||||
|
||||
@return A pointer to the object.
|
||||
*/
|
||||
T* get () const
|
||||
{
|
||||
return m_p;
|
||||
}
|
||||
|
||||
/** Retrieve the raw pointer.
|
||||
|
||||
@return A pointer to the object.
|
||||
*/
|
||||
T* operator* () const
|
||||
{
|
||||
return m_p;
|
||||
}
|
||||
|
||||
/** Retrieve the raw pointer.
|
||||
|
||||
@return A pointer to the object.
|
||||
*/
|
||||
T* operator-> () const
|
||||
{
|
||||
return m_p;
|
||||
}
|
||||
|
||||
/** Determine the number of references.
|
||||
|
||||
@note This is not thread-safe.
|
||||
|
||||
@return The number of active references.
|
||||
*/
|
||||
long use_count () const
|
||||
{
|
||||
return getRefCounts () [m_p];
|
||||
}
|
||||
|
||||
/** Release the pointer.
|
||||
|
||||
The reference count is decremented. If the reference count reaches
|
||||
zero, the object is deleted.
|
||||
*/
|
||||
void reset ()
|
||||
{
|
||||
if (m_p != 0)
|
||||
{
|
||||
if (--getRefCounts () [m_p] <= 0)
|
||||
delete m_p;
|
||||
|
||||
m_p = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
T* m_p;
|
||||
};
|
||||
|
||||
//==============================================================================
|
||||
|
||||
namespace luabridge
|
||||
{
|
||||
|
||||
template <class T>
|
||||
struct ContainerTraits <RefCountedPtr <T> >
|
||||
{
|
||||
typedef T Type;
|
||||
|
||||
static T* get (RefCountedPtr <T> const& c)
|
||||
{
|
||||
return c.get ();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user