Skip to content

Metadata

ashley edited this page Aug 19, 2026 · 4 revisions

A small amount of metadatas from Haxe are supported in HscriptInsanity scripts, along with some library-specific ones...

Supported Haxe metadata

  • @:bypassAccessor
  • @:forward(field1, field2) is supported in scripted abstract declarations
  • @:enum is supported to declare scripted enum abstracts (enum abstract also works and is preferrable however)

HscriptInsanity metadata

  • @:safe can be used in scripted class declarations to catch exceptions thrown from instances. In the case this occurs, onInstanceError will 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 may be impacted from caught exceptions.
  • @:snapshot can 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.

Clone this wiki locally