Created
June 22, 2013 06:11
-
-
Save gistya/5836069 to your computer and use it in GitHub Desktop.
Some util functions to help with LSL scripting using JSON
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //JSON_TYPE integers | |
| integer invalid = 1; //invalid | |
| integer object = 2; //object | |
| integer array = 4; //array | |
| integer number = 8; //number | |
| integer str = 16; //string | |
| integer null = 32; //null | |
| integer true = 64; //true | |
| integer false = 128; //false | |
| //map the json type to a useful bitmask lol | |
| integer jsonType(string json, list specifiers) { | |
| return llRound(llPow(2.,(float)((integer)llGetSubString( | |
| llEscapeURL(llJsonValueType(json,specifiers)),8,8)))); | |
| } | |
| //as long as it ain't null or invalid, returns true |=} | |
| integer jsonValid(string value, list spec) { | |
| return ( | |
| !( jsonType(value,spec) & (invalid | null) ) | |
| ); | |
| } | |
| string jsonGetValue(string json, list spec) { | |
| if(jsonValid(json,spec)) return llJsonGetValue(json,spec); | |
| else return ""; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment