Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: How to use CLR enum in script?

0
0
Hi qrli!

You want to keep the .NETish part as much as possible. But when we use scripts, we want to minimize that as much possible. In ideal case, script writers don't need to know .NET at all.

Agreed, but it isn't ClearScript's goal to provide ideal script APIs. Its goal is to make existing .NET APIs fully scriptable, and to make ideal script APIs easy to implement.

Consider a typical, non-trivial .NET API, complete with all its ".NETish parts". ClearScript aims to make such an API instantly scriptable, with full access to all its ".NET quirks". Replacing it with an ideal script API is something that (a) requires additional design effort by a human being, and (b) results in an API that is ideal only for the target script language. For these reasons it is outside the scope of the ClearScript project.

It is just like a web developer who works with the web page DOM, where the script writer does not need to know C++/COM nor follow C++/COM typing rules.

The DOM is a script API by design; a typical .NET API is not. Nothing stops you from implementing a DOM-like API layer using ClearScript. In fact, making that easy to do is one of ClearScript's goals.

ClearScript is analogous to COM Interop. That framework allows .NET code to access COM APIs. Does it turn COM APIs into ideal .NET APIs? Of course not. It can't, and it shouldn't. Full access comes with quirks.

All that having been said, it is absolutely a goal for ClearScript to make .NET scripting as natural as possible.

print("Key.Space = " + Key.Space); // result is "Key.Space = [object HostObject]"
print(Key.Space); // result is "Space"
You see the different results?

Yes, this makes sense. In the first line, the string concatenation is performed by the JavaScript engine, which calls toString() on each operand. To get the desired result, do this:
print("Key.Space = " + Key.Space.ToString());
It might be a good idea for ClearScript to implement toString() and eliminate the ambiguity. We'll take a look. Interestingly, JScript - which doesn't use HostObject wrappers - produces "Key.Space = undefined".

ScriptEngineException.ErrorDetails is null when an error happened inside an event callback function.
This only happens with JScriptEngine. V8ScriptEngine works fine.

Unfortunately Windows Script engines (JScript/VBScript) don't provide error details unless you enable debugging. To do so, pass WindowsScriptEngineFlags.EnableDebugging into the engine constructor.

Does ClearScript support or intend to support .NET's dynamic/expendo object? I mean, in natural script syntax.

Yes, we're working on this. Please see here.

It is possible to enable V8's harmony features?

Not currently. This is on our long-term to-do list.

Thanks again for all your input!

Viewing all articles
Browse latest Browse all 2297