Jump to content
  • Advertisement
Sign in to follow this  
Migi0027

Mono or Lua - Scripting

This topic is 2111 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

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

Edited by Migi0027

Share this post


Link to post
Share on other sites
Advertisement

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.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

Thanks for the replies,

 

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

 

Thanks guys!

Share this post


Link to post
Share on other sites

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.

Edited by mdias

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

 

 

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!