1
0
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:
Sandu Liviu Catalin
2016-06-09 03:01:19 +03:00
parent f1d8d60e96
commit a3169ad7d2
34 changed files with 7520 additions and 0 deletions

View File

@@ -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_