mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2026-01-20 22:24:38 +01:00
Various minor changes and fixes that were not pushed to the repository. Just random stuff.
This commit is contained in:
@@ -682,6 +682,32 @@ struct Var<Object&> : Var<Object> {Var(HSQUIRRELVM vm, SQInteger idx) : Var<Obje
|
||||
template<>
|
||||
struct Var<const Object&> : Var<Object> {Var(HSQUIRRELVM vm, SQInteger idx) : Var<Object>(vm, idx) {}};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Create a script object from the specified value on the default VM.
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
template < typename T > Object MakeObject(const T & v)
|
||||
{
|
||||
// Remember the current stack size
|
||||
const StackGuard sg;
|
||||
// Transform the specified value into a script object
|
||||
PushVar< T >(DefaultVM::Get(), v);
|
||||
// Get the object from the stack and return it
|
||||
return Var< Object >(DefaultVM::Get(), -1).value;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Create a script object from the specified value on the specified VM.
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
template < typename T > Object MakeObject(HSQUIRRELVM vm, const T & v)
|
||||
{
|
||||
// Remember the current stack size
|
||||
const StackGuard sg;
|
||||
// Transform the specified value into a script object
|
||||
PushVar< T >(vm, v);
|
||||
// Get the object from the stack and return it
|
||||
return Var< Object >(vm, -1).value;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// A lightweight wrapper arround the Squirrel objects that implements RAII and still remains a POD type.
|
||||
///
|
||||
@@ -799,6 +825,20 @@ struct LightObj {
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Constructs an LightObj from a C++ instance wrapped inside a DeleteGuard
|
||||
///
|
||||
/// \param instance Pointer to a C++ class instance that has been bound already
|
||||
/// \param v VM that the object will exist in
|
||||
///
|
||||
/// \tparam T Type of instance
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
template<class T>
|
||||
LightObj(DeleteGuard<T> guard, HSQUIRRELVM v = DefaultVM::Get()) : LightObj(guard.Get(), v) {
|
||||
guard.Release();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Destructor
|
||||
///
|
||||
@@ -927,6 +967,45 @@ struct LightObj {
|
||||
sq_pop(vm,1); // pop table
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Casts the object to a certain C++ type
|
||||
///
|
||||
/// \tparam T Type to cast to
|
||||
///
|
||||
/// \return A copy of the value of the Object with the given type
|
||||
///
|
||||
/// \remarks
|
||||
/// This function MUST have its Error handled if it occurred.
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
template <class T>
|
||||
T Cast() const {
|
||||
HSQUIRRELVM vm = DefaultVM::Get();
|
||||
sq_pushobject(vm, mObj);
|
||||
Var<T> v(vm, -1);
|
||||
sq_pop(vm, 1);
|
||||
return v.value;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Casts the object to a certain C++ type instance
|
||||
///
|
||||
/// \tparam T Type to cast to
|
||||
///
|
||||
/// \return A pointer to the value of the Object with the given type
|
||||
///
|
||||
/// \remarks
|
||||
/// This function MUST have its Error handled if it occurred.
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
template <class T>
|
||||
T * CastI() const {
|
||||
HSQUIRRELVM vm = DefaultVM::Get();
|
||||
sq_pushobject(vm, mObj);
|
||||
Var<T *> v(vm, -1);
|
||||
sq_pop(vm, 1);
|
||||
return v.value;
|
||||
}
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -974,6 +1053,84 @@ struct Var<LightObj&> : Var<LightObj> {Var(HSQUIRRELVM vm, SQInteger idx) : Var<
|
||||
template<>
|
||||
struct Var<const LightObj&> : Var<LightObj> {Var(HSQUIRRELVM vm, SQInteger idx) : Var<LightObj>(vm, idx) {}};
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Create a script object from the specified value on the default VM.
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
template < typename T > LightObj MakeLightObj(const T & v)
|
||||
{
|
||||
// Remember the current stack size
|
||||
const StackGuard sg;
|
||||
// Transform the specified value into a script object
|
||||
PushVar< T >(DefaultVM::Get(), v);
|
||||
// Get the object from the stack and return it
|
||||
return Var< LightObj >(DefaultVM::Get(), -1).value;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Create a script object from the specified value on the specified VM.
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
template < typename T > LightObj MakeLightObj(HSQUIRRELVM vm, const T & v)
|
||||
{
|
||||
// Remember the current stack size
|
||||
const StackGuard sg;
|
||||
// Transform the specified value into a script object
|
||||
PushVar< T >(vm, v);
|
||||
// Get the object from the stack and return it
|
||||
return Var< LightObj >(vm, -1).value;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Used to get and push pure script objects to and from the stack as references (HSQOBJECT is always a reference)
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
template<>
|
||||
struct Var<HSQOBJECT> {
|
||||
|
||||
HSQOBJECT value; ///< The actual value of get operations
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Attempts to get the value off the stack at idx as an HSQOBJECT
|
||||
///
|
||||
/// \param vm Target VM
|
||||
/// \param idx Index trying to be read
|
||||
///
|
||||
/// \remarks
|
||||
/// This function MUST have its Error handled if it occurred.
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
Var(HSQUIRRELVM vm, SQInteger idx) {
|
||||
if (SQ_FAILED(sq_getstackobj(vm, idx, &value))) {
|
||||
sq_resetobject(&value);
|
||||
} else {
|
||||
sq_addref(vm, &value);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Called by Sqrat::PushVar to put an HSQOBJECT on the stack
|
||||
///
|
||||
/// \param vm Target VM
|
||||
/// \param value Value to push on to the VM's stack
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
static void push(HSQUIRRELVM vm, const HSQOBJECT& value) {
|
||||
sq_pushobject(vm, value);
|
||||
}
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Used to get and push pure script objects to and from the stack as references (HSQOBJECT is always a reference)
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
template<>
|
||||
struct Var<HSQOBJECT&> : Var<HSQOBJECT> {Var(HSQUIRRELVM vm, SQInteger idx) : Var<HSQOBJECT>(vm, idx) {}};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Used to get and push pure script objects to and from the stack as references (HSQOBJECT is always a reference)
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
template<>
|
||||
struct Var<const HSQOBJECT&> : Var<HSQOBJECT> {Var(HSQUIRRELVM vm, SQInteger idx) : Var<HSQOBJECT>(vm, idx) {}};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user