Sign in to follow this  

Using Lua with C#

This topic is 3452 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm creating a game using C# and XNA and I'm looking for a scripting language to work with so I don't have to recompile everything every time I make a tiny adjustment. I googled around a bit and found something called the Lua interface. This is my first time using a scripting language and I'm wondering what exactly I have to do in order to be able to use this the way I want. All help is appreciated.

Share this post


Link to post
Share on other sites
LuaInterface is really easy to use.

Basically, you'll have a class containing all of your functions that you want to expose to the script, then you can do something like this:
LuaInterface.Lua luaObject = new LuaInterface.Lua();

luaObject.RegisterFunction("scriptFunctionName", myClass, myClass.GetType().GetMethod("nameOfFunctionInClass"));

luaObject.DoString(script);
luaObject.GetFunction("someFunctionInTheScript").Call();

Share this post


Link to post
Share on other sites
C# with dynamic code compilation is a nice approach, IMO. Unfortunately you can't do it on the Xbox 360, though (the dynamic code compilation classes aren't available).

Personally for my XNA game (for PC and 360) I just use all C# anyway. Most of the reasons I used to use embedding scripting languages with C++ is taken care of by reflection (runtime discovery of types, properties, methods).

EDIT: Also if you are indeed targeting the 360, you should make sure that LuaInterface doesn't depend on any native-code libraries. I'm not really familiar with it, so I'm not sure if it does. I'm sure someone else here knows. [smile]

Share this post


Link to post
Share on other sites
LuaInterface depends on native Lua, so it is not an
option for the Xbox either..

So if the OP wants scripting on the Xbox something else must
be thought of :)

Marc

Share this post


Link to post
Share on other sites
Quote:
Original post by marcjulian
LuaInterface depends on native Lua, so it is not an
option for the Xbox either..

So if the OP wants scripting on the Xbox something else must
be thought of :)

Marc


Ahh, that's too bad. Thanks for clearing that up. [smile]

Share this post


Link to post
Share on other sites

This topic is 3452 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this