Skip to content

Defining scripted types

ashley edited this page Aug 17, 2026 · 7 revisions

HscriptInsanity supports defining types (such as classes or enums) within scripts! Below is a comprehensive list of what you can do with this library...

Supported types in Hscript

Currently, you can define the following types in scripts...

Support for currently unsupported types is planned to be introduced in the near future.
Defining fields at module level is also supported within scripted modules!

Scripts

You can simply declare types within your scripts!

class Message {
	public var text:String;
	
	public function new(text:String) { this.text = text; }
	
	public function alert():String { trace(text); }
}

new Message('hello world!').alert(); // hello world!

The code example above should work correctly in a script.
The only caveat to doing this is that script defined types can't be imported in any other scripts by default (maybe obviously).

Modules

Modules work (almost) exactly the same you would expect in Haxe!
Look at the Loading scripts page to learn how to implement modules in your project.

Limitations

A handful of the issues below arise from type parameters being stripped at runtime.

  • Abstracts

    • Still rather experimental!!! You might encounter bugs or inconsistent behaviors for the time being, but they're still being fixed.
    • Typing may be degraded. This is also the case when using compiled abstracts.
  • Typedefs

    • Struct / json typedefs are parsed without errors but are not enforced or checked at runtime.

Clone this wiki locally