NQNStudios / hank

Portable narrative scripting language based on Ink.
MIT License
13 stars 3 forks source link

More powerful embedded Haxe #43

Closed NQNStudios closed 6 months ago

NQNStudios commented 5 years ago

I think it would be useful to have some Haxe features that hscript is missing, such as function and enum definitions especially, and the ability to invoke constructors and static methods.

So I'll be looking into forks/extensions/alternatives to hscript. The first one I checked out was ihx, which won't work because it depends on the system's Haxe and Neko binaries (which means it's not fully portable/cross-platform).

Edit: I was wrong. function definitions are allowed in hscript.

NQNStudios commented 5 years ago

A few things slipped my mind about what is/isn't possible in hscript. We previously discussed some of them in issue #16 and here's the link to hscript's limitations: https://github.com/HaxeFoundation/hscript#limitations. Best not to forget the details before making any big decisions.

NQNStudios commented 5 years ago

Also very important: https://github.com/HaxeFoundation/hscript#advanced-usage

What I'm trying to figure out now is if I can use Haxe apply macros at runtime in hscript to reimplement some of the janky code translations I've done in evaluateHaxeExpression() in saner ways.

NQNStudios commented 5 years ago

Hscript contains the function Macro.convert(e: hscript.Expr): Expr. What we need to make this possible is a reverse conversion, convert(e: haxe.macro.Expr): hscript.Expr. Then, we'll have access to the full suite of haxe expression reification tools in order to transmute embedded Haxe.

However, it might be simpler to attempt expression reification on hscript Expr's directly, rather than implement the reverse conversion.

NQNStudios commented 5 years ago

To take the simpler approach (using hscript Expr objects only) it seems the main transmutations would be trivial:

EVar(name, type, expression) tells the HInterface to declare a variable with that name in interp.variables, and change to EBinop(=, EIdent(name), expression)

EIdent(varname) can be transmuted to check if the varname refers to a viewcount

EBinop(&&, EIdent(varname), EIdent(varname2)) can be preprocessed to boolify viewcounts for &&'ing view counts as if they were bools, like the TODO comment here notes is currently impossible

NQNStudios commented 5 years ago

One thing I want to do that would require haxe macros is the idea of wrapping static classes like FlxG in object instances that can be passed to interp.variables. I think that that conversion doesn't need to happen at runtime, though, it can happen at compiletime for a Hankerchief game.

zicklag commented 5 years ago

Just found this and thought I'd point it out. Might be useful. :man_shrugging:

https://github.com/darmie/hxComposer

NQNStudios commented 5 years ago

That actually does look useful! The documentation is sparse/confusing but what I glean from the code looks nifty. I might spend some time in the next month or so looking it over.

NQNStudios commented 6 months ago

triaging this for now