tink_adhoc


https://github.com/haxetink/tink_adhoc/

To install, run:

haxelib install tink_adhoc 0.1.0 

See using Haxelib in Haxelib documentation for more information.

README.md

Tink Adhoc Implementations

This library provides a way to make adhoc implementations, very similar to Java's anonymous classes.

interface Enemy {
  
  var id(default, null):Int;
  var name(default, null):String;
  var level(get, never):Int;
  var hp(get, never):Int;

  function hit(dmg:Int):Void;
}

var level = 1;
var ogre = new tink.Adhoc<Enemy>({ hp: 100 }, {
  id: Std.random(1000000000),
  name: 'Ogre',
  level: {
    get: function (_) return level
  },
  hp: {
    get: function (state) return state.hp,
  }
  hit: function (state, dmg) state.hp -= dmg
});

The type parameter is the interface being implemented. As for constructor arguments, the first one is the adhoc instance's internal state, which gets passed to all methods and accessors as the first argument (you may call it as you wish). Notice that all implementations live in the very scope they were created in, so you can capture variables, access the outer this and so forth.

Adhoc subclassing is planned for a later time.

Contributors
back2dos
Version
0.1.0
Published
1 year ago
License
MIT

All libraries are free

Every month, more than thousand developers use haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on Github!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on Github