mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-11-30 13:07:19 +01:00
Partial implementation of the JSON module.
This commit is contained in:
@@ -4,6 +4,12 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Base/Utility.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <cstdlib>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <jansson.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
@@ -20,6 +26,80 @@ namespace SqMod {
|
||||
#define SQJSON_VERSION_MINOR 0
|
||||
#define SQJSON_VERSION_PATCH 1
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Implements RAII to free the strings obtained from dumps even after exceptions.
|
||||
*/
|
||||
struct CStrGuard
|
||||
{
|
||||
// --------------------------------------------------------------------------------------------
|
||||
CStr mPtr; // The managed pointer
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Base constructor.
|
||||
*/
|
||||
CStrGuard(CStr p)
|
||||
: mPtr(p)
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~CStrGuard()
|
||||
{
|
||||
if (mPtr)
|
||||
{
|
||||
std::free(mPtr);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Forward declarations.
|
||||
*/
|
||||
class JValue;
|
||||
class JArray;
|
||||
class JObject;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve the string representation of JSON value type.
|
||||
*/
|
||||
CSStr JSONTypeToStr(json_type type);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve the string representation of JSON value type.
|
||||
*/
|
||||
inline CSStr JSONTypeStr(json_t * ptr)
|
||||
{
|
||||
return (ptr == nullptr) ? _SC("unknown") : JSONTypeToStr(json_typeof(ptr));
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Convert a script value from the stack to a JSON object.
|
||||
*/
|
||||
json_t * SqToJSON(HSQUIRRELVM vm, SQInteger idx);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Convert a script table to a JSON object.
|
||||
*/
|
||||
JObject SqTableToJSONObject(Table & obj);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Convert a script array to a JSON array.
|
||||
*/
|
||||
JArray SqArrayToJSONArray(Array & obj);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Convert a script object to a JSON object.
|
||||
*/
|
||||
JObject SqObjectToJSONObject(Object & obj);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Convert a script value to a JSON value.
|
||||
*/
|
||||
JValue SqValueToJSONValue(Object & obj);
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _SQJSON_COMMON_HPP_
|
||||
|
||||
Reference in New Issue
Block a user