Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Math.cos example fails when targeting HashLink #96

Open
Arazati opened this issue Jul 21, 2020 · 3 comments
Open

Math.cos example fails when targeting HashLink #96

Arazati opened this issue Jul 21, 2020 · 3 comments

Comments

@Arazati
Copy link

Arazati commented Jul 21, 2020

While trying to follow the example code

var script = "
	var sum = 0;
	for( a in angles )
		sum += Math.cos(a);
	sum; 
";
var parser = new hscript.Parser();
var program = parser.parseString(script);
var interp = new hscript.Interp();
interp.variables.set("Math",Math); // share the Math class
interp.variables.set("angles",[0,1,2,3]); // set the angles list
trace( interp.execute(program) );

with latest haxe 4.1.2 and hashlink 1.11.0, I get the error "Invalid function null" when it tries to find the cos function in Math. This -appears- to be a hashlink bug? But I'm not entirely sure if maybe there's a way around it that should be done in hscript instead.

The code executes as expected with both js and interp.

Reflect.getProperty(Math, "cos"); //null for HashLink target
@ncannasse
Copy link
Member

ncannasse commented Jul 21, 2020

Try with -dce no maybe ?

@Arazati
Copy link
Author

Arazati commented Jul 21, 2020

-dce no exposes random, min, and max, but not cos and others (specifically, none of the @:hlNative functions get reflection)

@NotHyper-474
Copy link

NotHyper-474 commented Oct 13, 2024

Was investigating this bug and found a 4 year unresolved issue, sad.

I discovered that interestingly you can get around this by creating a class that wraps the inaccessible functions and use it instead of std.Math, like so:

class Mathf
{
  public static function abs(a:Float):Float
  {
    return Math.abs(a);
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants