mirror of
https://github.com/opensim/opensim.git
synced 2026-08-06 01:06:30 +08:00
Adds a couple requested functions to the JsonStore script
interface. JsonPathType returns the type of node pointed to by the path and deprecates the functionality of both JsonTestPath functions. JsonArrayLength returns the length of an array node.
This commit is contained in:
@@ -140,6 +140,34 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
|
||||
ValueStore = OSDParser.DeserializeJson(value);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
// -----------------------------------------------------------------
|
||||
public JsonStoreNodeType PathType(string expr)
|
||||
{
|
||||
Stack<string> path;
|
||||
if (! ParsePathExpression(expr,out path))
|
||||
return JsonStoreNodeType.Undefined;
|
||||
|
||||
OSD result = ProcessPathExpression(ValueStore,path);
|
||||
|
||||
if (result == null)
|
||||
return JsonStoreNodeType.Undefined;
|
||||
|
||||
if (result is OSDMap)
|
||||
return JsonStoreNodeType.Object;
|
||||
|
||||
if (result is OSDArray)
|
||||
return JsonStoreNodeType.Array;
|
||||
|
||||
if (OSDBaseType(result.Type))
|
||||
return JsonStoreNodeType.Value;
|
||||
|
||||
return JsonStoreNodeType.Undefined;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
/// <summary>
|
||||
///
|
||||
@@ -162,6 +190,27 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
|
||||
return false;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
// -----------------------------------------------------------------
|
||||
public int ArrayLength(string expr)
|
||||
{
|
||||
Stack<string> path;
|
||||
if (! ParsePathExpression(expr,out path))
|
||||
return -1;
|
||||
|
||||
OSD result = ProcessPathExpression(ValueStore,path);
|
||||
if (result != null && result.Type == OSDType.Array)
|
||||
{
|
||||
OSDArray arr = result as OSDArray;
|
||||
return arr.Count;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
/// <summary>
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user