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

@:posInfos to pass haxe.PosInfos to Reflect.makeVarArgs() #6696

Open
mastef opened this issue Oct 21, 2017 · 2 comments
Open

@:posInfos to pass haxe.PosInfos to Reflect.makeVarArgs() #6696

mastef opened this issue Oct 21, 2017 · 2 comments
Milestone

Comments

@mastef
Copy link
Contributor

mastef commented Oct 21, 2017

I think one of the most common use-cases for Reflect.makeVarArgs() would be for logging tools, and in the same breath one of the most common use-cases for haxe.PosInfos would be the usage in debug tools and loggers as well, since we can read out the line numbers of the call.

However those 2 don"t work well together, although you would expect that that"s how trace() works under the hood :

  • It can take any number of arguments
  • The last argument is PosInfos

Now currently if you want to replicate that behaviour, the only way is to redefine trace(). But in html5, you might not want to do that, since you don"t want to just log out to console.log - you want to log out to console.warn, console.error, console.debug, console.info etc. - and of course you want to attach the line number of the call to it.

So assuming there"s no other way to have a function with an arbitrary amount of arguments + haxe.PosInfos attached to it ( as it is in trace ), I would propose to add a @:posInfos metadata, that passes on haxe.PosInfos as the last parameter to a function when it"s called.

This would also make the usage of trace() more standard and understandable, and would help with alternative logger solutions without them all having to redefine trace and possibly colliding with each other.

If I"ve missed anything and there is actually another alternative solution please feel free to play around with this example : https://try.haxe.org/#361D7

@mastef mastef changed the title @:posInfos to pass haxe.PosInfos to Reflect.makeVarArgs() @:posInfos to pass haxe.PosInfos to Reflect.makeVarArgs() Oct 21, 2017
@back2dos
Copy link
Member

The try.haxe code is truncated.

@mastef
Copy link
Contributor Author

mastef commented Oct 21, 2017

Yes, not sure what"s happening there - it happened a few times today. I"ve updated the link.

@restorer made a nice version, and it might work the other way around - with a varArgs macro : http://try-haxe.mrcdk.com/#0947D

@Simn Simn added this to the Design milestone Apr 17, 2018
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