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

[lua] Incorrect arguments for object containing function #11901

Open
NeeEoo opened this issue Dec 22, 2024 · 1 comment
Open

[lua] Incorrect arguments for object containing function #11901

NeeEoo opened this issue Dec 22, 2024 · 1 comment

Comments

@NeeEoo
Copy link
Contributor

NeeEoo commented Dec 22, 2024

outputs

1, null
2, null
class Test {
	public var func:(Dynamic, Dynamic) -> Void;

	public function new(obj:Dynamic) {
		this.func = obj.test;
	}
	
	public function call(k:Dynamic, v:Dynamic) {
	     func(k, v);
	}
}

class Main {
	public static function main() {
		var a = new Test({
			test: function(k:Dynamic, v:Dynamic) {
				trace(k, v);
			}
		});
		a.func("a", 1);
		a.call("b", 2);
	}
}

meanwhile this works

class Main {
	public static function main() {
		var a = {
			test: function(k:Dynamic, v:Dynamic) {
				trace(k, v);
			}
		};

		a.test("a", 1);
	}
}

so somewhere between it going into a class breaks it

I believe this is due to it generating the function as

function(self, k, v)

generated code for first example:

Test.new = function(obj) 
  local self = _hx_new(Test.prototype)
  Test.super(self,obj)
  return self
end
Test.super = function(self,obj) 
  self.func = obj.test;
end
Test.__name__ = true
Test.prototype = _hx_e();
Test.prototype.func= nil;
Test.prototype.call = function(self,k,v) 
  self.func(k, v);
end

Test.prototype.__class__ =  Test

Main.new = {}
Main.__name__ = true
Main.main = function() 
  local a = Test.new(_hx_o({__fields__={test=true},test=function(self,k,v) 
    __haxe_Log.trace(k, _hx_o({__fields__={fileName=true,lineNumber=true,className=true,methodName=true,customParams=true},fileName="src/Main.hx",lineNumber=25,className="Main",methodName="main",customParams=_hx_tab_array({[0]=v}, 1)}));
  end}));
  a.func("a", 1);
  a:call("b", 2);
end

meanwhile second

Main.new = {}
Main.__name__ = true
Main.main = function() 
  (function(k,v) 
    __haxe_Log.trace(k, _hx_o({__fields__={fileName=true,lineNumber=true,className=true,methodName=true,customParams=true},fileName="src/Main.hx",lineNumber=25,className="Main",methodName="main",customParams=_hx_tab_array({[0]=v}, 1)}));
  end)("a", 1);
end
@EyeDaleHim
Copy link

Might be related: #10089

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

2 participants