Archived

This topic is now archived and is closed to further replies.

Eul0gy

C++ as Native Engine code and C# as Scripting

Recommended Posts

hey I have looking at the idea of implementing a scripting language into my demo''s i have been working on for uni which are in C++. I have been looking at Python and Lua but i have had classes in C# from uni. I was wondering if it would be possible to have C# as a Scripting language sitting above C++ code . the C++ code is Un managed. Would i have to change it to Managed code at all? cheers Eul0gy^

Share this post


Link to post
Share on other sites
I would imagine that C# could hypothetically be easier to embed, as managed C++ is much closer to the Way It Should Be than the Python/C API. (where the Way It Should Be is defined as using code from language A in language B without any work being done on bindings)

C# makes a terrible scripting language, though. It has so much syntactic overhead that you really shouldn''t have to deal with. (public static void blah....)

"Without deviation, progress itself is impossible." -- Frank Zappa

Share this post


Link to post
Share on other sites
You don''t embedded C#, you embedded the CLR (Common Language Runtime), which means they can use any .Net language to script your game - you can load any .Net assembly. The .Net platform comes with VB and C# compilers built-in though. (It''s called Hosting the CLR if you want to read more about it).

Share this post


Link to post
Share on other sites
VB.NET can be more script-like with Option Strict and Option Explicit turned off. Of course hosting the CLR will give you the option to use whatever .NET language you'd like to.


Epolevne

[edited by - Epolevne on March 19, 2004 2:33:06 PM]

Share this post


Link to post
Share on other sites
I cannot remember for sure if the C# compiler classes are part of the .NET runtime, or only the .NET SDK ... I thought they we''re SDK only.

Which would mean:

no, you CANNOT use C# as a scripting langauge ... because you can only compile C# if the client machine has the .NET SDK installed ... the COMPILER is FREE but included in the .NET SDK, but NOT the runtime.

Now if I am wrong, and the .NET classes to compile C# are in the CLR, then you could use it as a scripting language. And it really might be ... I''ll look it up and post later if someone doesn''t beat me to it.

Share this post


Link to post
Share on other sites
Well regardless CodeDOM is part of the runtime, so there

Although I see no reason NOT to include the Microsoft.* stuff in the runtime, in fact that would probably piss alot of people off.

People like me.

Share this post


Link to post
Share on other sites
quote:
Original post by Xai no, you CANNOT use C# as a scripting langauge ... because you can only compile C# if the client machine has the .NET SDK installed ... the COMPILER is FREE but included in the .NET SDK, but NOT the runtime.


The compiler is actually included in the runtime. There are parts of the framework that relies on it, like XML serialization.



--
AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.
[Project site] [Blog] [RSS] [Browse the source] [IRC channel]

Share this post


Link to post
Share on other sites
Now, I use C# as a kind of scripting language and it works quite well. I use it for scripting within a game, where I load several scripts at once, compile them using the C# Compiler classes and invoke the code of the created assembly. Works fine for me. Furthermore I put the compiled assemblies in a separate AppDomain so I''m even able to unload the scripts, e.g. after a level.
If you have this kind of scripts (i.e. quite static), using the built-in compiler works perfectly.
If you need a more dynamic scripting language, i.e. reacting on user input, I''d suggest the System.Reflection.Emit classes using a dynamic assembly. I haven''t experimented very much with it, bit I''d guess they are faster for high-frequent script input as you can extend an existing assembly instead of always creating a new one.
The only Problem with Reflection.Emit is that you can only emit IL-statements. I would find it very cool if there was a C# to IL parser built in. However it isn''t - or I haven''t found it. What you can do is build your own small scripting language and a parser that can create IL-code and use System.Reflection.Emit to dynamically create runtime-usable types and methods. After all, .NET has a HUGE potential for scripting.

Regards,
Andre (VizOne) Loker

Share this post


Link to post
Share on other sites
hey Arild, you are right, but I hate being selectively quoted like that ... if you read my post it says ... IF the compiler is in the runtime (which it may be) then it should work ...

and it is, as you said, and it does, as you said ... but you definately made it appear that I made a statement I didin''t ... through context ... I said ... " cannot remember for sure if the C# compiler classes are part of the .NET runtime" .. and then said IF NOT it wouldn''t work

Share this post


Link to post
Share on other sites
VizOne: are you sure you can extend existing assemblies using Emit? I really dont think so... afaik you have to create your own dynamic assembly, with dynamic types, etc.

I have been quite much looking for a scripting (i.e. dynamically typed and reloadable) language within .NET, yet I haven`t found any. The only one I found was "Python for .NET", which in fact is just a binding between the CPython and CLR. Not that it was bad, but it means you can not really create a managed class with the script, etc... There is a project of managed Python, called IronPython, but is in early stage of development.

But in case you are developing a C/C++ application and look for a scripting language, definitely embed Python.

Share this post


Link to post
Share on other sites