Giter Club home page Giter Club logo

Comments (8)

RealyUniqueName avatar RealyUniqueName commented on June 26, 2024 3

Initial implementation is done. All Haxe tests passed.

from haxe.

mockey avatar mockey commented on June 26, 2024 1

Array: not so good this way, see #32.

I don't know if you saw it, but I added @:phpGlobal metadata to genphp:
HaxeFoundation#5071
which I think is quite useful for handling global functions.

My idea for a php std lib was to take all the global functions (at least the most important ones) and generate externs for them with @:phpGlobal. Not sure about renaming some inconsistent function names, though. Also some functions that carry a resource around (like cURL) are good candidates for an abstract.

from haxe.

benmerckx avatar benmerckx commented on June 26, 2024

I've had a look at implementing Array. There's a lot of methods which can be inlined in the extern class. For example:

extern class Array<T> {

    var length(get, never) : Int;
    inline function get_length() : Int
        return untyped __call__('count', this);

    inline function concat( a : Array<T> ) : Array<T>
        return untyped __call__('array_merge', this, a);

    inline function join( sep : String ) : String
        return untyped __call__('implode', sep, this);

    inline function pop() : Null<T>
        return untyped __call__('array_pop', this);

    inline function push(x : T) : Int
        return untyped __call__('array_push', this, x);

    inline function shift() : Null<T>
        return untyped __call__('array_shift', this);

    inline function slice( pos : Int, ?end : Int ) : Array<T>
        return untyped __call__('array_slice', this, pos, end);
    ...
}

But then there's a few more methods which cannot be inlined and need a proper implementation. In other targets, which do not type it as a class, extra array methods are defined as static methods in another class. In python defined as python.internal.ArrayImpl and for JS as HxOverrides.

Defining the array as an abstract could work as well, but the typer refuses to accept that.

File "src/typing/typer.ml", line 5378, characters 2-8: Assertion failed

How would you like to handle these situations?

from haxe.

RealyUniqueName avatar RealyUniqueName commented on June 26, 2024

It would be great to inline Array methods because arrays used alot in almost any app. Could you please move your comment to a new issue to make sure your idea won't be lost?

from haxe.

RealyUniqueName avatar RealyUniqueName commented on June 26, 2024

I saw it, but i thought the purpose is to make any static function a global function. Which looked weird for me :)
But if it's for externs only, then it sounds like an interesting idea. Is there any difference between @:phpGlobal and an extern class with inlined implementations?
E.g.

extern class Preg {
  static inline function replace (haystack:Strimg, pattern:String, replacement:String) : String {
    return untyped __call__('preg_replace', pattern, replacement, haystack);
  }
}

from haxe.

mockey avatar mockey commented on June 26, 2024

It was meant for externs only because I got tired of writing this untyped __call__ stuff. Also untyped __call__ generates quite complex expressions for the compiler, it's not a real extern this way.

As far as I understood Simn is also not happy with these magic functions, they lead to quite a lot of problems. I don't know if the newer generators (python, lua) have other solutions for this.

from haxe.

mockey avatar mockey commented on June 26, 2024

I defined Superglobals like this:

@:phpGlobal
extern class Superglobal {
  @:native("_SERVER")
  static var SERVER:NativeArrayA<Dynamic>;
  ...
}

Not quite right, but you get the meaning.

from haxe.

mockey avatar mockey commented on June 26, 2024

Also I added some code to genphp for global constants, so that you can do e.g.:

@:phpGlobal
@:phpConstants("\\SOAP_SSL_METHOD_")
@:enum extern abstract SoapSslMethod(Int) {
  var TLS;
  var SSLv2;
  var SSLv3;
  var SSLv23;
}

Magic constants:

@:phpGlobal
@:phpConstants
extern class MagicConstant {
  @:native("__FUNCTION__")
  static var FUNCTION:String;
 ...
}

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.