1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 08:47:17 +01:00
SqMod/modules/json/JValue.cpp
Sandu Liviu Catalin 66d1110733 Rvised the API distribution system to avoid segmentation fault crashes on Linux and make the overal code cleaner.
Moved the constants in IRC module into their own source and implemented a faster method of registering them.
Various other minor changes and adjustments. Some of them in order to comply with the new API distribution system.
2016-07-17 03:24:07 +03:00

66 lines
2.4 KiB
C++

// ------------------------------------------------------------------------------------------------
#include "JValue.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
std::size_t JValue::s_Flags = JSON_ENCODE_ANY;
// ------------------------------------------------------------------------------------------------
SQInteger JValue::Typename(HSQUIRRELVM vm)
{
static const SQChar name[] = _SC("SqJSONValue");
sq_pushstring(vm, name, sizeof(name));
return 1;
}
// ------------------------------------------------------------------------------------------------
Object JValue::ToString() const
{
// Dump the values to a string
const CStrGuard csg(json_dumps(m_Ptr, s_Flags));
// Remember the current stack size
const StackGuard sg;
// Transform the string into a script object
sq_pushstring(DefaultVM::Get(), csg.mPtr ? csg.mPtr : _SC(""), -1);
// Return the created script object
return Var< Object >(DefaultVM::Get(), -1).value;
}
// ------------------------------------------------------------------------------------------------
Object JValue::GetValue() const
{
return Object();
}
// ================================================================================================
void Register_JValue(Table & jns)
{
jns.Bind(_SC("Value"), Class< JValue >(jns.GetVM(), _SC("SqJSONValue"))
// Constructors
.Ctor()
.Ctor< const JValue & >()
// Core Meta-methods
.Func(_SC("_cmp"), &JValue::Cmp)
.SquirrelFunc(_SC("_typename"), &JValue::Typename)
.Func(_SC("_tostring"), &JValue::ToString)
// Properties
.Prop(_SC("IsObject"), &JValue::IsObject)
.Prop(_SC("IsArray"), &JValue::IsArray)
.Prop(_SC("IsString"), &JValue::IsString)
.Prop(_SC("IsInteger"), &JValue::IsInteger)
.Prop(_SC("IsReal"), &JValue::IsReal)
.Prop(_SC("IsNumber"), &JValue::IsNumber)
.Prop(_SC("IsTrue"), &JValue::IsTrue)
.Prop(_SC("IsFalse"), &JValue::IsFalse)
.Prop(_SC("IsBoolean"), &JValue::IsBoolean)
.Prop(_SC("IsNull"), &JValue::IsNull)
.Prop(_SC("Value"), &JValue::GetValue)
// Member Methods
//.Func(_SC("Func"), &JValue::Func)
);
}
} // Namespace:: SqMod