Giter Club home page Giter Club logo

Comments (17)

RealyUniqueName avatar RealyUniqueName commented on June 25, 2024

JS target uses the same approach: untyped __js__('alert(1)')

from haxe.

Simn avatar Simn commented on June 25, 2024

untyped is bad for various reasons. It would be better to hide this as Lib.code('') or something to that extent.

from haxe.

RealyUniqueName avatar RealyUniqueName commented on June 25, 2024

So should new generator support untyped or implement somethind like Lib.code() instead?

from haxe.

Simn avatar Simn commented on June 25, 2024

I guess we should still support untyped __php__ but encourage the alternative.

from haxe.

RealyUniqueName avatar RealyUniqueName commented on June 25, 2024

So what's the approved alternative? )

from haxe.

Simn avatar Simn commented on June 25, 2024

I don't really have a strong opinion about that, any normal field call will do.

from haxe.

mockey avatar mockey commented on June 25, 2024

I think php.Lib.code is short and clear.
Can you use php as PHP namespace BTW?

from haxe.

mockey avatar mockey commented on June 25, 2024

Additionally php.Lib.call maybe var should be done differently, physeq is not needed I think. At least it wasn't in the old phpgen, don't know how you handle equality.

from haxe.

nadako avatar nadako commented on June 25, 2024

In python we have python.Syntax and there's stuff for generating python expressions.

from haxe.

nadako avatar nadako commented on June 25, 2024

I don't really see how it would make much difference compared to untyped though. It can be even worse, because untyped __php__ is an unbound var, while something like php.Syntax.pythonCode is a normal function call from the analyzer POV, and it's going to make assumptions that it's a normal call, not something "magic" that is handled in the generator.

from haxe.

Simn avatar Simn commented on June 25, 2024

Yes but this allows us to introduce some @:magic metadata for the analyzer. In the long run I would like to get rid of unbound variables entirely.

from haxe.

programmatix avatar programmatix commented on June 25, 2024

Have you guys looked at the solutions used by Typescript and scala.js for this general problem of calling into untyped external code? I know they're JS rather than PHP, but it's the same basic issue. They let you define a typed interface, like this scala.js for the Google maps JS lib:

trait MapOptions extends js.Object {
  var backgroundColor: String = js.native
  var center: LatLng = js.native
  var disableDefaultUI: Boolean = js.native
  var disableDoubleClickZoom: Boolean = js.native
...
}

I know it seems a bit of a pain, but they don't take long to knock up, and Typescript has a cool shared repo of these interfaces for all kinds of JS libraries.

You can then call methods and create objects from those JS libraries in a type-safe way, and the generated code is optimal too.

from haxe.

programmatix avatar programmatix commented on June 25, 2024

untyped is my biggest pain point currently (I'm writing a Wordpress plugin in Haxe and need to call into Wordpress functions loads) and I'd love to see it get a lot slicker. To take another example from how scalajs handles things, if you don't setup an interface (as above), you can just do this:

var arg2 = 3;
js.Dynamic.global.some_external_func("arg1", arg2)

Admittedly there's no more type-safety than with untyped, and scala.js has no idea whether some_external_func exists and how many args it takes, I just think it's a bit easier to read and write that than:

untyped __php__('some_external_func("arg1", $arg2)');

I can more easily see the arguments, at least. Maybe this syntactic sugar is possible?

from haxe.

benmerckx avatar benmerckx commented on June 25, 2024

Haxe has the same concept called externs: https://haxe.org/manual/lf-externs.html

from haxe.

programmatix avatar programmatix commented on June 25, 2024

Ah amazing, thank you. I'm very new to Haxe, these look great.

from haxe.

RealyUniqueName avatar RealyUniqueName commented on June 25, 2024

Here is an example: https://github.com/RealyUniqueName/haxe/blob/php7/std/php7/reflection/ReflectionProperty.hx
And here is original PHP class: http://php.net/manual/en/class.reflectionproperty.php

from haxe.

RealyUniqueName avatar RealyUniqueName commented on June 25, 2024

Implemented php7.Syntax which purpose is to replace all untyped code: https://github.com/RealyUniqueName/haxe/blob/php7/std/php7/Syntax.hx

from haxe.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.