Skip to content

Instantly share code, notes, and snippets.

@skial
Created December 8, 2011 23:08
Show Gist options
  • Save skial/1449156 to your computer and use it in GitHub Desktop.
Save skial/1449156 to your computer and use it in GitHub Desktop.
Near to minimal php as possible - minimal code example
package ;
/**
* ...
* @author Skial Bainn
*/
extern class Date {
// http://www.php.net/manual/en/function.mktime.php
public inline function new(year : Int, month : Int, day : Int, hour : Int, min : Int, sec : Int ):Void {
return untyped __call__("mktime", hour, min, sec, month+1, day, year);
}
public inline function getTime():Float {
return untyped this * 1000;
}
}
<?php
class Main {
public function __construct(){}
static function main() {
// this to be in its place - mktime(15, 25, 0, 12, 8, 2011)
$date = new Date(2011, 12, 8, 15, 25, 0);
$date * 1000;
}
function __toString() { return 'Main'; }
}
?>
package ;
import php.Lib;
/**
* ...
* @author Skial Bainn
*/
class Main {
public static function main():Void {
var date = new Date(2011, 12, 08, 15, 25, 0);
date.getTime();
}
}
@skial
Copy link
Author

skial commented Dec 8, 2011

I currently need to output minimal code and files, so converting some haxe classes to output direct php methods, instead of the haxe generated classes which basically wrap the same php methods.

Every inline method gets generated correctly apart from the constructor, so I currently use a static method named init or similar to start everything.

I don't think I would be able to get around this using macros, if it is - just say and I'll start digging, but I think the compiler would complain of a missing constructor.

  • Would this be acceptable to have in the compiler? Is it to much of an edge case to be bothered with?
  • Or would it be possible to use a patch file to tell the compiler what method to use instead of generating new? example:

// pseudo // replace.patch Date.new : static Date.init
As far as I can tell from looking at http://haxe.org/manual/swc and http://code.google.com/p/haxe/source/browse/trunk/doc/extract.patch I don't see anything like this, correct me if I'm wrong :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment