• Advertisement
Sign in to follow this  

Mono or Lua - Scripting

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

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

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

I like using Lua. It is very easy to understand and very flexible. You can make arrays work the way you want them to (doesn't use arrays, uses tables) and you can make classes work the way you want them to (no object oriented programming, so no classes, but you can fake it easily). 

Share this post


Link to post
Share on other sites

I like Lua since the simple nature of it forces you to think carefully what to do with scripts and what to do with c/c++ for example. as mentioned Lua tables are very flexible and pretty fast so you can do a lot of crazy things with them.

 

In my current project I do all the per frame update stuff with c++ and Lua just take care of callbacks and define objects

Share this post


Link to post
Share on other sites

LUA as well :) It's easy, small and fast. And most of all, it makes me feel like its just a small addition to the rest of my code and not some bloated monster that wants to take over and dominate everything.

Share this post


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

  • Advertisement