2

I'm programming a computer game in C#/Mono using OpenTK library. I want to use Lua for scripting for the game, so also those who know nothing about C# can edit the scripts, levels, etc. However, the problem is, that I can't find any way how to use Lua with C#/Mono. I found amazing LuaInterface, however it doesn't work on Mono. I've tried it and it works on Windows, but it doesn't on linux (Ubuntu). Replacing lua51.dll with linux alternates doesn't simply work.

I'd like to ask if there's any suitable way for using LuaInterface with Mono (I didn't find any source codes of LuaInterface to edit and rebuild it; I also heard that old versions of LuaInterface do work on Mono, however I didn't find them anywhere for download), or if there's any other suitable library for C#/Mono that you used before and you know it works. I've been searching for a long time, but I didn't find anything and I don't want to spend weeks programming it myself.

I guess it'd be however possible to use C# for scripting rather than Lua, but I don't like that idea very much, although I don't know why.

Community
  • 1
  • 1
TomsonTom
  • 742
  • 7
  • 22

2 Answers2

2

There is a feature in .Net (which is also included in Mono) called Dynamic Language Runtime.

I don't know about Lua being supported, but there are DLR implementations of Python and Ruby - both of these work on Mono as well as on Microsoft CLR.

Check out this question for information about using C# as scripting language.

EDIT: Actually, there is an IronLua project, but I don't know how complete it is.

Community
  • 1
  • 1
Matěj Zábský
  • 16,909
  • 15
  • 69
  • 114
  • I've voted up for your answer, however I don't want to use DLR, because it enables anyone to use your application as a host for one's virus, spyware, etc. If I use DLR, C# and I let anyone to edit scripts and publish them, then anyone can script anything using system libraries (removing system files, killing processes, uninstalling applications, etc.) So, would it be possible to use DLR, but restrict access to only some libraries? I hope you understand what I mean. – TomsonTom Jan 21 '12 at 13:44
  • 1
    @TomsonTom You can host the script in an AppDomain with reduced privileges. See this: http://msdn.microsoft.com/en-us/library/bb763046.aspx and this: http://stackoverflow.com/questions/1362757/how-to-host-an-ironpython-engine-in-a-separate-appdomain – Matěj Zábský Jan 21 '12 at 13:53
  • Thanks, I've accepted your asnwer as it seems to be the only solution for me. :) – TomsonTom Jan 21 '12 at 14:02
1

You can use lua grammar and this answer as way to find compiler generator which creates c# code. As I think it is the best and the easiest way to make support for external language support. Why? You can fast add any events for grammatic constructions and add any language extensions you want.

Community
  • 1
  • 1
FLCL
  • 2,445
  • 2
  • 24
  • 45
  • Implementing language from grammar (even using a parser generator) is much more complex than using existing implementation where you just declare function and variable bindings and you are done. Not to mention that writing efficient compiler and VM is rather complex task - that is something you have to build yourself above the parser created with the parser generator. – Matěj Zábský Jan 21 '12 at 11:40
  • Described way's advantage depends on project size and projects needs. And I also think that it is not too hard to solve problem using this technology, it may takes a couple of days learning and a half of weak to develop. – FLCL Jan 21 '12 at 11:52
  • Thanks for your idea, but I'm not going to do something complex like this. But I voted up, 'cause it's a working solution. :) – TomsonTom Jan 21 '12 at 13:46