Mono or Lua - Scripting

Started by
11 comments, last by Acharis 10 years, 3 months ago

Hi guys,

so currently I've got a very vague implementation of Mono Embedded C#, and also of Lua, but I'd rather focus on on or the other. I've been focusing on mono, but I'm slowly realizing that it gets complicated, especially because of the data types which needs to be passed between c# and c++. On the other hand Lua hasn't really been troubling me, and I really like the syntax and everything, it's simple and fast.

so I've considered completely removing (or just disabling) the Mono Embedded Runtimes, and focusing completely on using Lua as a scripting language.

What are your opinions on this?

Thank you for your time.

-MIGI0027

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

Advertisement

Lua

Depends entirely on what you're using your scripting for. If you plan to implement large amounts of code in script - especially performance-sensitive stuff - then go Mono. If you're just using it for glue and high-level logic, the ease of integrating Lua is nice.

Sean Middleditch – Game Systems Engineer – Join my team!

I would say Lua JIT would be the way to go and then you can drop Mono completely.

I never worked with Lua, but worked with mono for a considerable while, and I loved most of it. I just had a base class that dealt with the object glue (store a pointer to the native object, get the native object from the mono object and that kind of stuff) and passed structs by ref between native<->script with no problem at all. Even arrays were pretty easy to pass from C++ to Mono

What kind of datatypes are you having trouble with?

Thanks for the replies,

mdias: I've had trouble passing pointers to mono for some reason, how did you do it?

Thanks guys!

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

You mean pointers to structs or to objects?

Here's an example of me passing a pointer to a C++ on-stack struct:


bool RayCastResults::call_internalAddResultOrdered( RayCastResult& result )
{
	MonoObject* excep = nullptr;

	MonoObject* resObject = mono_value_box( _domain, _classResult, &result );

	_method_internalAddResultOrdered( _obj, resObject, &excep );
	if( excep )
	{
		mono_print_unhandled_exception( excep );
		return false;
	}

	return true;
}

"_classResult" is: "_classResult = mono_class_from_name_case( img, "Engine.Physics", "RayCastResult" );"

Which on C# side is:


using System;
using System.Collections.Generic;

namespace Engine
{
	namespace Physics
	{
		public class RayCastResults
		{
			private void internal_AddResultOrdered( RayCastResult result )
			{
				...
			}
		}

		public struct RayCastResult
		{
			public override string ToString()
			{
				return string.Format("[RayCastResult] distance: {0}", distance);
			}

			public float distance;
			public CollisionObject body;
			public Shape shape;
			public Vector3 normalWorld;
			public Vector3 pointWorld;
		}
	}
}

If passing a pointer to an object, you just need to pass the MonoObject* pointer. Sometimes it's a good idea to have internal methods on C# side where you do some processing on the C++ passed data before calling the real final method.

Thanks for the info, I'll test it soon.

What about if I keep Mono for the game mechanics, like generating the world and the game logic, and Lua for objects/actors which do not need complicated tasks.

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

I just noticed I posted an example passing the struct by value instead of reference. I don't have the code at hand but as far as I remember, to pass as reference you just pass a normal C++ pointer as an argument to the method.


What about if I keep Mono for the game mechanics, like generating the world and the game logic, and Lua for objects/actors which do not need complicated tasks.

Like I said, I never worked with Lua, so I'm not familiar with it's strengths or weaknesses. However, it looks weird to me that different parts of the engine are scripted with different languages.

I don't know if it applies to your project, but I'd abstract away all interactions with scripting so you could script any part of the engine with any or multiple implementations (including Mono, Lua and others) with relative ease. Maybe this way you could stick to just one of the scripting engines like you want and implement an other at a later stage if the need arises.

Regarding "Lua vs Mono" I believe you'll have to tell more about the kind of project you're working on.

Regarding "Lua vs Mono" I believe you'll have to tell more about the kind of project you're working on.

Well, I like to say I'm building an engine, though I develop on this engine as my game develops, like I suddenly realize, I need "that", so, I go and implement it and use it.

Though in the beginning till now I've just been trying to implement features and working on the flexibility of the engine, and now I'm actually starting doing something with it, in this case, a small game.

But, the small project I'm currently doing is a sandbox, where the player can place any objects and create his own shapes and stuff, it's still very vague, but I'm liking the progress. So I'd like to move the whole world generation and logic to a scripting environment.

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

This topic is closed to new replies.

Advertisement