SPOD macro and php

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

SPOD macro and php

Julien CASTETS
Hi Guys,

I almost made work the spod_macro thing targeting php.

I'm sharing with you to get your advises which could really help.

My struggles:

* The use of what I'll call the "prototype trick".
class_proto.prototype._manager = this;
...
untyped __dollar__objsetproto(x,class_proto.prototype);

From what I understand this allow to modify an object prototype at runtime and is neko specific because "prototype" is null when targeting php.
What I'm not sure about is "Will new instances of this prototype be affected without?" my guess is yes. (Ok I could write a simple test code to be sure)
Anyway I found solutions that are target specific using the Reflection API.

* Macros
This is my first attempt writing macros, so I think it's normal. I used macros to provide a part of solution to workaround the prototype trick.
BTW haxe macros are awesome =)

* Static init in php
This is the unsolved thing. I faced that trying the @:relation thing. In php Static members of a class will be initialized when you "require_once" the class file. This cause an initialization list to be empty when it should be populated. (ie sys.db.Manager::init_list).
As a temporary workaround, the first thing I do in the entry point is to call the constructors of each of my spod objects.
ie:
new SpodTypes();
new SpodTypesRelation();
sys.db.Manager.initialize();


Maybe I could find a way to automatically "require_once" the needed stuff but I guess this issue should be addressed to Franco since it appears to be a more general one and not only a spod_macro_php one.

I'm attaching a patch, just for review, if you mind, I'll be glad.

Thank you
Best
Julien

--
haXe - an open source web programming language
http://haxe.org

php_spod_macro_patch.patch (9K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: SPOD macro and php

Nicolas Cannasse
Le 29/08/2011 15:44, Julien CASTETS a écrit :

> Hi Guys,
>
> I almost made work the spod_macro thing targeting php.
>
> I'm sharing with you to get your advises which could really help.
>
> My struggles:
>
> * The use of what I'll call the "prototype trick".
> class_proto.prototype._manager = this;
> ...
> untyped __dollar__objsetproto(x,class_proto.prototype);

You have to look at how the current php.db.Manager handle this.

Nicolas

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: SPOD macro and php

Nicolas Cannasse
In reply to this post by Julien CASTETS
Le 29/08/2011 15:44, Julien CASTETS a écrit :
> Hi Guys,
>
> I almost made work the spod_macro thing targeting php.

I've commited changes, please test with it.

For prototypes, it's now using a single initialization in the sys.db.Object.

For relations, it's now generating two methods : get_xxx and set_xxx
that will call the target relation manager __get and __set methods.

Best,
Nicolas

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: SPOD macro and php

Nicolas Cannasse
Le 11/09/2011 14:40, Nicolas Cannasse a écrit :

> Le 29/08/2011 15:44, Julien CASTETS a écrit :
>> Hi Guys,
>>
>> I almost made work the spod_macro thing targeting php.
>
> I've commited changes, please test with it.
>
> For prototypes, it's now using a single initialization in the
> sys.db.Object.
>
> For relations, it's now generating two methods : get_xxx and set_xxx
> that will call the target relation manager __get and __set methods.

I've also added support for blob mapping to haxe.io.Bytes.

In php/_std/sys/db/Mysql.hx (convert) :
        case "blob": return haxe.io.Bytes.ofData(v);

Franco, could you confirm it's the right way to do it ?

Best,
Nicolas




--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: SPOD macro and php

Franco Ponticelli
It seems to be correct.

Franco

On Sun, Sep 11, 2011 at 2:12 PM, Nicolas Cannasse <[hidden email]> wrote:
Le 11/09/2011 14:40, Nicolas Cannasse a écrit :

Le 29/08/2011 15:44, Julien CASTETS a écrit :
Hi Guys,

I almost made work the spod_macro thing targeting php.

I've commited changes, please test with it.

For prototypes, it's now using a single initialization in the
sys.db.Object.

For relations, it's now generating two methods : get_xxx and set_xxx
that will call the target relation manager __get and __set methods.

I've also added support for blob mapping to haxe.io.Bytes.

In php/_std/sys/db/Mysql.hx (convert) :
       case "blob": return haxe.io.Bytes.ofData(v);

Franco, could you confirm it's the right way to do it ?


Best,
Nicolas




--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org