🔒 Locked
Using Lua with C#
Advertisement
Original Post
Comments for the article Using Lua with C#
Thanks, this is awesome and could save me a bunch of work.
I was looking at Iron Python too though. It is written natively in C# and so might be embedded easily too.
Has anyone used python? How easy is it to use compared to lua?
Has anyone used python? How easy is it to use compared to lua?
Quote:
Original post by Anonymous Poster
Could you please explain or provide a link to some info?
System.CodeDom.Compiler.CodeDomProvider
System.CodeDom.Compiler.ICodeCompiler
A Simple C# Compiler Without Using csc.exe
Yes, but some developers would like to give the users a more flexible language like lua for example. And lua is used by more and more applications for a scripting language.
Although I am the kind of person that would preffer c# over lua for scripts, mostly because I am a programmer that feels much more confortable with c like syntax and a strongly typed environment
Although I am the kind of person that would preffer c# over lua for scripts, mostly because I am a programmer that feels much more confortable with c like syntax and a strongly typed environment
Quote:
Original post by BradSnobar
I was looking at Iron Python too though. It is written natively in C# and so might be embedded easily too.
There's no need to "embed" Iron Python; as a first-class .NET language, it can consume assemblies generated by other .NET languages and generate assemblies for consumption by other .NET assemblies seamlessly.
Quote:
Has anyone used python? How easy is it to use compared to lua?
Python is bigger than Lua, though generally slower as well. It has far more functionality, being a standalone language right from its original conception, rather than an extension/data configuration format like Lua. The traditional trade-off has been the feature-richness of Python for a performance hit and difficulty integrating with C++ or the bare-bones simplicity of Lua for a cinch to build. With Iron Python and the CLR, the integration becomes a non-factor, leaving you with robust features, and since your code can be JIT compiled just like C#...
By default, though, your code is interpreted, which makes it a very quick way to prototype and/or develop code that requires a lot of hand massaging.
I use Lua and C# together a lot - I think they're a great match :D
It's very easy to generate lua code on the fly and use lua's tables for storage. Also the first class nature of the functions makes some stuff much simpler to write.
(I also like passing back more than one return value - it's make many things that are usually tricky just dissapear)
And I've written a much more basic introduction here.
[Edited by - Balaam on February 7, 2006 6:44:41 AM]
It's very easy to generate lua code on the fly and use lua's tables for storage. Also the first class nature of the functions makes some stuff much simpler to write.
(I also like passing back more than one return value - it's make many things that are usually tricky just dissapear)
And I've written a much more basic introduction here.
[Edited by - Balaam on February 7, 2006 6:44:41 AM]
You'd use LUA instead of C# code because you might need to reload the script at some point while the program is still running. In the .NET framework there's no way to unload assemblies unless you create a new application domain and then destroy it when you're done. Very wasteful and hackey.
Hi, I am the author of LuaInterface, the library this article uses. Previous releases of LuaInterface have focused on making it easier to use .NET assemblies from Lua, as this is the use case I thought would be more common (building prototypes, using .NET as a GUI for Lua programs, writing computation-intensive code in C# for speed, and calling it from Lua, etc.), but it appears there is a lot of interest in embedding Lua in .NET applications! I am working on the next release, and will include the suggestions in this article, and hopefully make LuaInterface even better for the embedding folks.
--
Fabio Mascarenhas, Lablua, PUC-Rio
--
Fabio Mascarenhas, Lablua, PUC-Rio
I'm using LuaInterface for my .NET game engine project.
So far it is working well for me and native <-> lua interactions work great.
One thing I found annoying was figuring out the compat library stuff. Documentation on how to get .NET assembly/type importing to work could be better. Right now I just have the compat library in the same directory as my exe and I basically messed with stuff until it worked.
Anyway, I'm looking forward to future releases! Don't give up on this project, it has great potential.
So far it is working well for me and native <-> lua interactions work great.
One thing I found annoying was figuring out the compat library stuff. Documentation on how to get .NET assembly/type importing to work could be better. Right now I just have the compat library in the same directory as my exe and I basically messed with stuff until it worked.
Anyway, I'm looking forward to future releases! Don't give up on this project, it has great potential.
Quick comment, having non-stateless stuff static doesnt make for good reusability. What if you want more than one instance of the lua vm?
Edit: Also, I would name the attributes the way microsoft's named the ones in the dotnet framework. For example, I'd name AttrLuaFunc LuaFunctionAttribute, which would mean it can be used as [LuaFunction(...)]. A lot more elegant.
[Edited by - Lantz on November 14, 2005 7:58:08 AM]
Edit: Also, I would name the attributes the way microsoft's named the ones in the dotnet framework. For example, I'd name AttrLuaFunc LuaFunctionAttribute, which would mean it can be used as [LuaFunction(...)]. A lot more elegant.
[Edited by - Lantz on November 14, 2005 7:58:08 AM]
Quote:
Original post by Anonymous Poster
It's one of the dumbest things I've ever read. So, ignoring that Lua is a complete pile of crap language, IMO, what's the point? You can compile and run C# code at run-time, and reload the assemblies at will making C# into a scripting language.
Now by using Lua with C# you're using a scripting language within another scripting language. People that have to maintain your crappy code now have to learn two languages one of which is a complete pile of trash.
Just because Blizz uses Lua in a hugely popular game doesn't mean that it's a great language; it just means that somebody's experiment got published.
Wow! That's smart!
First of all, C# isn't a "scripting language". Don't be ignorant and stupid at the same time.
C#.NET is compiled into ILasm, which the .NET Virtual Machine then interprets at runtime. VB.NET, C++.NET, etc, all get compiled into the same code, ILasm.
Second of all, allowing a game engine have the fuctionality of all of .NET's framework is a security risk. With a scripting language, you get to choose what is compiled and what not.
If a game engine is going to allow modding by end users (and not just developers, like 'programmers'), Lua would be an appropriate scripting language to use, since its used in other games (like WoW I believe someone said). Your engine's reply value depends on your players, and if your players know how to create new content, they're going to want to do more with it (assuming your game is actually fun.
The guy took some time to at least write a decent tutorial, try giving some constructive criticism next time.
Quote:
Original post by Anonymous Poster
2kornman00:
You have to learn .NET before making such considerations.
.NET does NOT inrerpret IL code at runtime !!! Java does, .NET does not.
Instead, .NET framework does compile IL code into native machine code with JIT compiler and then execute it. This give a perforance like you write entire code in C++ !
Whats your definition of "interpret" :p
It still has to interpret the IL code once to turn it into native code at runtime.
Quote:
Each method for which Microsoft intermediate language (MSIL) has been generated is just-in-time-compiled (JIT-compiled) when it is called for the first time, and then run.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement