-
Notifications
You must be signed in to change notification settings - Fork 0
Advanced Key Syntax
Let us summarize all JSON key features:
1. Key Command
A simple RichJSON command that takes a struct as input:
"#<command_name>:key": { ...params... }
2. Constructor
The Constructor called and joined with the given struct:
normal: { "key=<class_name>": { ... } }
late: { "key==<class_name>": { ... } }
3. Inheritance
Inheritance is basically a concatenation of RichJSON commands.
They are joined from left to right, and finally the given struct is joined as well:
{ "key::#ref:path/to/struct, #file:path/to/file, ... <commands>": { ... } }
4. Interface
Interfaces allow you to implement multiple interfaces at once, applied from left to right:
normal: { "key;MyInterface1, MyInterface2, ... <interfaces>": { ... } }
late: { "key;;MyInterface1, MyInterface2, ... <interfaces>": { ... } }
It’s not a coincidence that these features are listed here because yes, you can use them all at once.
But be careful: these features can only be combined in the correct order.
Let me give you some examples:
Important
If you want to know what #twin does, check out this page.
function Coord2() constructor {
x = 0;
y = 0;
length_xy = function() { return sqrt(sqr(x) + sqr(y)); }
}
function ILoggable() constructor {
ctor {
__log_string = undefined;
}
get_log_string = function() {
if (__log_string == undefined)
__log_string = $"{MY_CLASS_NAME} {some_variable} {some_status}";
return __log_string;
}
}
{
"some_struct": {
"y": 10
},
"#twin:example1=Coord2": {
"x": 20,
"y": 20
},
"#twin:example2=Coord2::some_struct": {
"x": 20
},
"example3=Coord2::some_struct;ILoggable": {
"x": 20
}
}Note
No late applyment features were used here, except for the #twin command.
{
"some_struct": {
"y": 10
},
"example1": { // "#twin:example1=Coord2"
"x": 20,
"y": 20,
"length_xy": function() { return sqrt(sqr(x) + sqr(y)); }
},
"example2": { // "#twin:example2=Coord2::some_struct"
"x": 20,
"y": 10,
"length_xy": function() { return sqrt(sqr(x) + sqr(y)); }
},
"example3": { // "example3=Coord2::some_struct;ILoggable"
"x": 20,
"y": 10,
"length_xy": function() { return sqrt(sqr(x) + sqr(y)); },
"__log_string": undefined,
"get_log_string": function() {
if (__log_string == undefined)
__log_string = $"{MY_CLASS_NAME} {some_variable} {some_status}";
return __log_string;
}
}
}Author’s Recommendation: next read: Late Applying
Back to Repo ● Wiki Home
Copyright © coldrock.games