Embed phalanger & inject an object in scripting context

Integrating PHP and C# together. Using .NET libraries from PHP and vice versa.

Re: Embed phalanger & inject an object in scripting context

Postby nelson4070 » April 26th, 2013, 5:30 pm

Is there any way to force compiler configuration loading ? Due to my setup of mono, I think I need to manually initialize the compiler with the classLibrary.

EDIT : I managed to manually load PhpNetClassLibrary and make var_dump work by calling the following code

Code: Select all
_context.ApplicationContext.AssemblyLoader.Load(new[] { new CompilationParameters.ReferenceItem() {
                LibraryRoot = ".",
                Reference = "PhpNetClassLibrary, Version=3.0.0.0, Culture=neutral, PublicKeyToken=4af37afe3cde05fb" }
            });


Now this code (.net property call) gives an error :
Code: Select all
$test = $browser->Window;


Code: Select all
System.InvalidCastException: Cannot cast from source type to destination type.

at PHP.Core.PhpVariable.IsEmpty (object) <0x001b1>
at PHP.Core.Binders.PhpGetMemberBinder.<FallbackInvokeMember>b__6 (object) <0x00013>
at (wrapper dynamic-method) object.CallSite.Target (System.Runtime.CompilerServices.Closure,System.Runtime.CompilerServices.CallSite,object,PHP.Core.Reflection.DTypeDesc) <0x0003f>
at System.Dynamic.UpdateDelegates.UpdateAndExecute2<object, PHP.Core.Reflection.DTypeDesc, object> (System.Runtime.CompilerServices.CallSite,object,PHP.Core.Reflection.DTypeDesc) <0x003c7>
at <php^1>.<Global>.<php^1>.<Main> (PHP.Core.ScriptContext,System.Collections.Generic.Dictionary`2<string, object>,PHP.Core.Reflection.DObject,PHP.Core.Reflection.DTypeDesc,bool) <0x001ed>
at PHP.Core.DynamicCode.EvalInternal (string,string,string,PHP.Core.EvalKinds,PHP.Core.ScriptContext,System.Collections.Generic.Dictionary`2<string, object>,PHP.Core.Reflection.DObject,PHP.Core.Reflection.DTypeDesc,PHP.Core.Reflection.SourceCodeDescriptor,bool,PHP.Core.NamingContext) <0x00360>
at PHP.Core.DynamicCode.Eval (string,bool,PHP.Core.ScriptContext,System.Collections.Generic.Dictionary`2<string, object>,PHP.Core.Reflection.DObject,PHP.Core.Reflection.DTypeDesc,string,int,int,int,PHP.Core.NamingContext) <0x000b3>
at Kimono.Host.PhpInterpreter.Eval (string) <0x0002f>
at Kimono.Host.PhpInterpreter..ctor (Kimono.Dom.IDomBrowser) <0x001ab>
at Kimono.Sandbox.Run (Kimono.Dom.IDomBrowser) <0x000af>


EDIT :

I think that in PhpGetMemberBinder.FallbackInvokeMember the test
Code: Select all
if ((obj = target.Value as DObject) != null)
is false while it should be true. Is there an easy way to debug that ?

EDIT :

target.Value is not a CLRObject but my .net type, how to wrap it ?

FINAL EDIT :

Found it (thx to the source being open !) : I needed to wrap the browser object like that :

Code: Select all
PHP.Core.Operators.SetVariable(_context, null, "browser", ClrObject.Wrap(browser));


Maybe the documentation should be updated ?
nelson4070
 
Posts: 7
Joined: April 19th, 2013, 1:04 am

Re: Embed phalanger & inject an object in scripting context

Postby Jakub Misek » April 27th, 2013, 9:53 am

Excellent! I've realized once I saw this
Code: Select all
if ((obj = target.Value as DObject) != null)


I'm glad you've found it, great work!

Thanks,
Jakub Misek │ DEVSENSE s.r.o. | @misekjakubjakub@devsense.com
User avatar
Jakub Misek
 
Posts: 2092
Joined: January 4th, 2012, 2:42 pm
Location: Prague

Previous

Return to PHP/C# interoperability

Who is online

Users browsing this forum: No registered users and 1 guest

cron

User Control Panel

Login

Who is online

In total there is 1 user online :: 0 registered, 0 hidden and 1 guest (based on users active over the past 5 minutes)
Most users ever online was 89 on October 15th, 2018, 4:06 pm

Users browsing this forum: No registered users and 1 guest