Skip to content

Instantly share code, notes, and snippets.

@back2dos
Created December 15, 2013 18:56
Show Gist options
  • Select an option

  • Save back2dos/7976696 to your computer and use it in GitHub Desktop.

Select an option

Save back2dos/7976696 to your computer and use it in GitHub Desktop.
#if macro
import haxe.macro.Expr;
#else
class Image {
static public function img_tag(rr:RR, image: {path:String, w:Int, h:Int}, target_size):String {
return '<img alt="whoops">';
}
}
#end
typedef RR = Dynamic;
typedef SImage = {
name:String,
path:String,
w:Int,
h:Int
};
class Run {
macro static public function imageHTML(rr:ExprOf<RR>, name:String, target_size: ExprOf<String>):ExprOf<String> {
function getImage(name):SImage
return {
name : 'name',
path : 'path',
w : 0,
h : 0,
}
var image = { expr: ECheckType(macro $v{getImage(name)}, macro : Run.SImage), pos: haxe.macro.Context.currentPos() };
return macro{ Image.img_tag(${rr}, $image, $target_size ); };
}
static function main() {
imageHTML({}, 'foo', 'large');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment