You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I managed to find a solution that worked for me - so this is more of a question about the documentation.
Specifically - in the documentation I pasted below - it seems to be prescribing users of JINT to use SetValue(..) to bind a specific class or else use the javascript function:
importNamespace('<namespace>').
But, it seems like we don't actually need to "go into a javascript context" and instead we can just :
var namespaceName = "<some namespace>";
NamespaceReference namespaceReference = new NamespaceReference(engine, namespaceName);
engine.Realm.GlobalObject.Set(namespaceName, namespaceReference);
I'm not sure if there is some reason we shouldn't be binding the namespace this way (i.e. referencing the GlobalObject and just setting the namespace). If there isn't any reason we shouldn't be doing it this way - I'd recommend updating the documentation - since I think the more common use case for users would be to stay in a C# context for the binding of the namespace.
Here is the documentation I'm referencing:
When allowing the CLR, you can optionally pass custom assemblies to load types from.
var engine = new Engine(cfg => cfg
.AllowClr(typeof(Bar).Assembly)
);
and then to assign local namespaces the same way System does it for you, use importNamespace
jint> var Foo = importNamespace('Foo');
jint> var bar = new Foo.Bar();
jint> log(bar.ToString());
adding a specific CLR type reference can be done like this
engine.SetValue("TheType", TypeReference.CreateTypeReference(engine, typeof(TheType)))
and used this way
jint> var o = new TheType();
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I managed to find a solution that worked for me - so this is more of a question about the documentation.
Specifically - in the documentation I pasted below - it seems to be prescribing users of JINT to use SetValue(..) to bind a specific class or else use the javascript function:
But, it seems like we don't actually need to "go into a javascript context" and instead we can just :
I'm not sure if there is some reason we shouldn't be binding the namespace this way (i.e. referencing the GlobalObject and just setting the namespace). If there isn't any reason we shouldn't be doing it this way - I'd recommend updating the documentation - since I think the more common use case for users would be to stay in a C# context for the binding of the namespace.
Here is the documentation I'm referencing:
Beta Was this translation helpful? Give feedback.
All reactions