Updated sqrat dependency.

This commit is contained in:
Patrix
2022-07-11 03:11:17 +02:00
parent eab3d7c831
commit 71ce6652cc
3 changed files with 83 additions and 73 deletions

View File

@@ -65,6 +65,5 @@
#include "sqrat/sqratUtil.h"
#include "sqrat/sqratScript.h"
#include "sqrat/sqratArray.h"
#include "sqrat/sqratNull.h"
#endif

View File

@@ -1,72 +0,0 @@
//
// sqratNull: nullptr support
//
//
// Copyright (c) 2009 Brandon Jones
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
#if !defined(_SCRAT_NULL_H_)
#define _SCRAT_NULL_H_
#include <cstddef> // std::nullptr_t
#include "sqratTypes.h"
namespace Sqrat {
template<>
struct Var<std::nullptr_t> {
std::nullptr_t value; ///< The actual value of get operations
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Attempts to get the value off the stack at idx as an nullptr
///
/// \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 !defined (SCRAT_NO_ERROR_CHECKING)
SQObjectType value_type = sq_gettype(vm, idx);
if (value_type != OT_NULL) {
SQTHROW(vm, FormatTypeError(vm, idx, _SC("null")));
}
#endif
value = nullptr;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Called by Sqrat::PushVar to put an nullptr on the stack
///
/// \param vm Target VM
/// \param value Value to push on to the VM's stack
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static void push(HSQUIRRELVM vm, const std::nullptr_t value) {
sq_pushnull(vm);
}
};
}
#endif

View File

@@ -35,6 +35,7 @@
#include <squirrel.h>
#include <string>
#include <cstddef> // std::nullptr_t
#include "sqratClassType.h"
#include "sqratUtil.h"
@@ -567,6 +568,46 @@ SCRAT_INTEGER(signed __int64)
SCRAT_FLOAT(float)
SCRAT_FLOAT(double)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Used to get and push nullptr to and from the stack
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template<>
struct Var<std::nullptr_t> {
std::nullptr_t value; ///< The actual value of get operations
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Attempts to get the value off the stack at idx as an nullptr
///
/// \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 !defined (SCRAT_NO_ERROR_CHECKING)
SQObjectType value_type = sq_gettype(vm, idx);
if (value_type != OT_NULL) {
SQTHROW(vm, FormatTypeError(vm, idx, _SC("null")));
}
#endif
value = nullptr;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Called by Sqrat::PushVar to put an nullptr on the stack
///
/// \param vm Target VM
/// \param value Value to push on to the VM's stack
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static void push(HSQUIRRELVM vm, const std::nullptr_t value) {
sq_pushnull(vm);
}
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Used to get and push bools to and from the stack
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -811,6 +852,48 @@ struct Var<const string&> {
}
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Used to get and push SQUserPointer to and from the stack
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template<>
struct Var<SQUserPointer> {
SQUserPointer value; ///< The actual value of get operations
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Attempts to get the value off the stack at idx as a SQUserPointer
///
/// \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) {
SQUserPointer sqValue;
#if !defined (SCRAT_NO_ERROR_CHECKING)
if (SQ_FAILED(sq_getuserpointer(vm, idx, &sqValue))) {
SQTHROW(vm, FormatTypeError(vm, idx, _SC("userpointer")));
}
#else
sq_getuserpointer(vm, idx, &sqValue);
#endif
value = sqValue;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Called by Sqrat::PushVar to put a SQUserPointer on the stack
///
/// \param vm Target VM
/// \param value Value to push on to the VM's stack
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static void push(HSQUIRRELVM vm, const SQUserPointer value) {
sq_pushuserpointer(vm, value);
}
};
#ifdef SQUNICODE
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Used to get and push std::string to and from the stack when SQChar is not char (must define SQUNICODE)