Skip to content

Metadata

ashley edited this page Aug 21, 2026 · 3 revisions

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

Supported Haxe metadata

  • @: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
  • @:structInit is supported in scripted class declarations
  • @:enum is supported to declare scripted enum abstracts
    • enum modifier also works and should be preferred; this only exists for compatibility...

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 could become more unpredictable after an exception catch.

  • @: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.

    To order a snapshot in your code, you can call Environment.snapshot(), or Module.snapshot() for a specific module! This will allow the state to be restored next initialization. You can access all snapshots in the static variable Module.snapshots.

Clone this wiki locally