-
Notifications
You must be signed in to change notification settings - Fork 0
Metadata
A small amount of metadatas from Haxe are supported in HscriptInsanity scripts, along with some library-specific ones...
-
@:bypassAccessor- This is only enforced on scripted fields and real classes' private fields can still be accessed without it (this may change in the future?)
-
@:forward(field1, field2)is supported in scripted abstract declarations -
@:structInitis supported in scripted class declarations -
@:enumis supported to declare scripted enum abstracts-
enummodifier also works and should be preferred; this only exists for compatibility...
-
-
@:safecan be used in scripted class declarations to catch exceptions thrown from instances. In the case this occurs,onInstanceErrorwill be called on the scripted class implementation.@:safe class SafeClass { public function new():Void { throw 'this should be caught!'; } }
Do keep in mind that the interpreter's behavior could become more unpredictable after an exception catch.
-
@:snapshotcan be used in scripted class and abstract declarations to "record" static variables. Must a module be reloaded at any point, the previous state of a static variable should be restored when this metadata is used.class TestClass { @:snapshot public static var counter:Int = 0; // you can use the metadata in a field declaration... public function increaseCounter():Void { counter ++; } } // ...or in a class declaration instead, to record every static field! @:snapshot class TestClass { ... }
Do note this is only guaranteed to work properly with Haxe types / source compiled classes, and behavior may become undefined when recording variables that store scripted types.
To order a snapshot in your code, you can call
Environment.snapshot(), orModule.snapshot()for a specific module! This will allow the state to be restored next initialization. You can access all snapshots in the static variableModule.snapshots.
HscriptInsanity by emi3