Comments (8)
Initial implementation is done. All Haxe tests passed.
from haxe.
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.
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.
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.
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.
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.
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.
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)
- Rename things which has names conflicting with PHP
- Write typed arrays in docblocks
- NativeStructArray HOT 6
- UTF-8 aware String functions HOT 4
- PSR-4 / PSR-1 Compliance HOT 2
- External storage for class metadata and reflexion HOT 2
- Call Boot initialization in each loaded class HOT 1
- Don't pass `null` for calls with missing optional args HOT 1
- App entry point. HOT 1
- Support String fields for Dynamic values HOT 1
- Cast HOT 1
- Exception, file is not generated HOT 1
- Map iteration HOT 2
- Invoke native PHP class constants HOT 2
- Special class for PHP syntax implementation HOT 1
- Avoid excess unsets HOT 1
- Add new reserved keywords from PHP 7.1 HOT 1
- Investigate StringBuf optimizations
- Mention `-D php7` in haxe manual
- Infinite recursion in `trace()` if object has circular references.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from haxe.