Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions .github/workflows/build-samples.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Builds the sample projects on multiple targets to check for compiler errors.

name: Build Samples

on:
#push:
pull_request:
workflow_dispatch:

jobs:
build:
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
target: [cpp, html5, hl]
fail-fast: false

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v6.0.2

- name: Setup Haxe
uses: FunkinCrew/ci-haxe@v3
with:
haxe-version: 4.3.7

- name: Setup HMM
run: |
haxelib --global --quiet --never update haxelib
haxelib --global fixrepo
haxelib --global --quiet install hmm
haxelib --global run hmm setup

- name: Install sample dependencies
working-directory: ./samples
run: |
haxe run.hxml
hmm install --quiet
haxelib fixrepo

- name: Build Flixel Sample
working-directory: ./samples/flixel
run: |
haxelib run lime build ${{ matrix.target }} --no-output

- name: Build ZIP Flixel Sample
working-directory: ./samples/flixel_zip
run: |
haxelib run lime build ${{ matrix.target }} --no-output

- name: Build Heaps Sample
if: matrix.target == 'hl'
working-directory: ./samples/heaps
run: |
haxe hl.hxml

# - name: Build NME Sample
# if: matrix.target != 'hl'
# working-directory: ./samples/nme
# run: |
# hmm install --quiet
# haxelib update
# echo y | haxelib run nme build ${{ matrix.target }}

- name: Build OpenFL Sample
working-directory: ./samples/openfl
run: |
haxelib run openfl build ${{ matrix.target }} --no-output

- name: Build OpenFL (Firetongue) Sample
working-directory: ./samples/openfl_firetongue
run: |
haxelib run openfl build ${{ matrix.target }} --no-output

- name: Build OpenFL (HScript) Sample
working-directory: ./samples/openfl_hscript
run: |
haxelib run openfl build ${{ matrix.target }} --no-output

- name: Build OpenFL (HScript with Classes) Sample
working-directory: ./samples/openfl_hscript_class
run: |
haxelib run openfl build ${{ matrix.target }} --no-output


3 changes: 3 additions & 0 deletions include.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<!-- These values are added to the project XML when you include this library. -->
<haxelib name="jsonpath" />
<haxelib name="jsonpatch" />
<haxelib name="thx.core" />
<haxelib name="thx.semver" />

<haxeflag name="--macro" value="polymod.hscript._internal.HScriptRedirectDefines.run()" if="POLYMOD_REDIRECT_HSCRIPT" />
Expand Down
2 changes: 1 addition & 1 deletion polymod/Polymod.hx
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ class Polymod
#if hscript_typer
polymod.hscript._internal.PolymodTyperEx.clearAllModules();
#end
polymod.hscript.HScriptable.ScriptRunner.clearScripts();
polymod.hscript.ScriptRunner.clearScripts();
}

/**
Expand Down
15 changes: 10 additions & 5 deletions polymod/backends/HEAPSBackend.hx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ class HEAPSBackend implements IBackend
throw 'Function not implemented';
}

public function listLibraries():Array<String>
{
throw 'Function not implemented';
}

public function getPath(id:String):String
{
throw 'Function not implemented';
Expand Down Expand Up @@ -229,7 +234,7 @@ class ModFileEntry extends BytesFileEntry
var dirPath = isDir ? path : Util.uPathPop(fullFilePath);

var itemPaths = [];
for (id in p.type.keys())
for (id in p.assetTypes.keys())
{
if (id.indexOf(dirPath) != 0) continue;
if (Util.isMergeOrAppend(id)) continue;
Expand Down Expand Up @@ -290,16 +295,16 @@ class ModFileEntry extends BytesFileEntry
return super.getBytes();
}

override function readByte():Int
override function readBytes(out:Bytes, outPos:Int, pos:Int, len:Int):Int
{
initBytes();
return super.readByte();
return super.readBytes(out, outPos, pos, len);
}

override function read(out:Bytes, pos:Int, size:Int)
override function readFull(bytes:Bytes, pos:Int, len:Int)
{
initBytes();
return super.read(out, pos, size);
return super.readFull(bytes, pos, len);
}

override function loadBitmap(onLoaded:LoadedBitmap->Void):Void
Expand Down
1 change: 1 addition & 0 deletions polymod/backends/LimeBackend.hx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import unifill.Unifill;
import lime.app.Future;
import lime.graphics.Image;
import lime.net.HTTPRequest;
import lime.system.ThreadPool;
import lime.text.Font;
import lime.utils.Assets;
import lime.utils.Bytes;
Expand Down
5 changes: 5 additions & 0 deletions polymod/backends/NMEBackend.hx
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ class NMEBackend implements IBackend
throw 'Function not implemented';
}

public function listLibraries():Array<String>
{
throw 'Function not implemented';
}

public function getPath(id:String):String
{
throw 'Function not implemented';
Expand Down
6 changes: 3 additions & 3 deletions polymod/backends/PolymodAssetLibrary.hx
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ class PolymodAssetLibrary
return backend.loadSound(id);
}
#end
#end

/**
* @return A list of asset libraries for this framework.
Expand All @@ -521,7 +522,6 @@ class PolymodAssetLibrary
{
return backend.listLibraries();
}
#end

/**
* Get the absolute system file path for a given asset ID.
Expand Down Expand Up @@ -943,7 +943,7 @@ class PolymodAssetLibrary
typeLibraries.get('default').push(file);
}

#if openfl
#if (openfl && !nme)
if (assetType == FONT)
{
var font = Font.fromFile(this.file(file, modDir));
Expand Down Expand Up @@ -1009,7 +1009,7 @@ class PolymodAssetLibrary
assetTypes.set(f, assetType);
if (!typeLibraries.exists(libraryId)) typeLibraries.set(libraryId, []);
typeLibraries.get(libraryId).push(f);
#if openfl
#if (openfl && !nme)
if (assetType == FONT)
{
var font = Font.fromFile(file(f, redirectPath));
Expand Down
133 changes: 0 additions & 133 deletions polymod/hscript/HScriptable.hx
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package polymod.hscript;

import haxe.Json;
import polymod.hscript._internal.Expr;
import polymod.Polymod;
import polymod.util.Util;

/**
* This interface triggers the execution of a macro on any elements which use the `@:hscript` annotation.
Expand Down Expand Up @@ -171,133 +168,3 @@ class HScriptParams
return Json.stringify(this);
}
}

typedef ScriptOutput =
{
/**
* The output of the script. Can be any value type.
*/
var script_result:Dynamic;

/**
* The functions and variables created within the scope of the script.
*/
var script_variables:Map<String, Dynamic>;
}

class ScriptRunner
{
/**
* No reason not to make this static! Load a script once instead of 50 times.
*/
private static var scripts:Map<String, Script> = new Map<String, Script>();

public function new() {}

public static function clearScripts():Void
{
scripts.clear();
}

public function load(name:String, assetHandler:Dynamic):Null<Script>
{
if (assetHandler == null)
{
Polymod.error(SCRIPT_NO_ASSET_HANDLER, "Class does not import an Assets class for Polymod to fetch scripts with!", SCRIPT_RUNTIME);
return null;
}

var scriptPath = scriptPath(name);
Polymod.debug('Fetching script "$scriptPath"...');
if (!assetHandler.exists(scriptPath))
{
// Error will only be thrown if hscriptParams.optional == false (the default).
Polymod.debug('Note: Script at path "$scriptPath" not found! This may cause problems if it is not optional...');
return null;
}

var script = new Script(assetHandler.getText(scriptPath));
scripts.set(name, script);
Polymod.debug('Script $name loaded successfully.');
return script;
}

static inline function scriptPath(pathName:String):String
{
return Util.pathJoin('${PolymodConfig.scriptLibrary}:${PolymodConfig.rootPath}', '$pathName${PolymodConfig.scriptExt}');
}

public function get(name:String, ?assetHandler:Dynamic = null):Null<Script>
{
// If the script isn't loaded yet, do that now.
if (!scripts.exists(name))
{
Polymod.debug('Scripted function loaded late (this is fine if the pathname is dynamic).');
load(name, assetHandler);
}

var result = scripts.get(name);

if (result == null)
{
// An error will only be thrown if hscriptParams.optional == false (the default).
return null;
}

return scripts.get(name);
}

public function execute(name:String, ?assetHandler:Dynamic = null):ScriptOutput
{
var script = get(name, assetHandler);
if (script == null)
{
Polymod.error(SCRIPT_NOT_FOUND, 'Could not load script $name for execution.', SCRIPT_RUNTIME);
}
return script.execute();
}
}

class Script
{
private static var parser:polymod.hscript._internal.Parser;

public var program:Expr;
public var interp:polymod.hscript._internal.Interp;

public static function buildParser():polymod.hscript._internal.Parser
{
return new polymod.hscript._internal.Parser();
}

public static function buildInterp():polymod.hscript._internal.Interp
{
// Arguments are only needed in a scripted class context.
return new polymod.hscript._internal.Interp(null, null);
}

public function new(script:String, ?origin:String = null)
{
if (parser == null)
{
parser = buildParser();
parser.allowTypes = true;
}
program = parser.parseString(script, origin);
interp = buildInterp();
}

public function set(key:String, value:Dynamic)
{
interp.variables.set(key, value);
}

public function execute():ScriptOutput
{
var result:Dynamic = interp.execute(program);
return {
script_result: result,
script_variables: interp.variables,
};
}
}
Loading
Loading