Jump to content

  • Log In with Google      Sign In   
  • Create Account

Mono or Lua - Scripting


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
12 replies to this topic

#1 Migi0027   Crossbones+   -  Reputation: 1724

Like
0Likes
Like

Posted 03 January 2014 - 02:58 PM

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, 03 January 2014 - 02:59 PM.

Hi! Cuboid Zone
The Rule: Be polite, be professional, but have a plan to kill everyone you meet, ohh, AND STEAL ALL ZE TRIANGLES FROM ZHEM!

Sponsor:

#2 rpiller   Members   -  Reputation: 683

Like
0Likes
Like

Posted 03 January 2014 - 06:30 PM

Lua



#3 SeanMiddleditch   Members   -  Reputation: 5761

Like
1Likes
Like

Posted 03 January 2014 - 06:49 PM

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.



#4 rpiller   Members   -  Reputation: 683

Like
0Likes
Like

Posted 03 January 2014 - 06:55 PM

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



#5 mdias   Members   -  Reputation: 788

Like
0Likes
Like

Posted 03 January 2014 - 09:58 PM

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?



#6 Migi0027   Crossbones+   -  Reputation: 1724

Like
0Likes
Like

Posted 04 January 2014 - 03:15 AM

Thanks for the replies,

 

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

 

Thanks guys!


Hi! Cuboid Zone
The Rule: Be polite, be professional, but have a plan to kill everyone you meet, ohh, AND STEAL ALL ZE TRIANGLES FROM ZHEM!

#7 mdias   Members   -  Reputation: 788

Like
0Likes
Like

Posted 04 January 2014 - 07:35 AM

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, 04 January 2014 - 10:44 AM.


#8 Migi0027   Crossbones+   -  Reputation: 1724

Like
0Likes
Like

Posted 04 January 2014 - 10:42 AM

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.


Hi! Cuboid Zone
The Rule: Be polite, be professional, but have a plan to kill everyone you meet, ohh, AND STEAL ALL ZE TRIANGLES FROM ZHEM!

#9 mdias   Members   -  Reputation: 788

Like
0Likes
Like

Posted 04 January 2014 - 12:47 PM

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.



#10 Migi0027   Crossbones+   -  Reputation: 1724

Like
0Likes
Like

Posted 04 January 2014 - 02:44 PM

 

 

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.


Hi! Cuboid Zone
The Rule: Be polite, be professional, but have a plan to kill everyone you meet, ohh, AND STEAL ALL ZE TRIANGLES FROM ZHEM!

#11 Tutorial Doctor   Members   -  Reputation: 1621

Like
0Likes
Like

Posted 04 January 2014 - 03:02 PM

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). 


They call me the Tutorial Doctor.


#12 Kristoffer   Crossbones+   -  Reputation: 839

Like
0Likes
Like

Posted 05 January 2014 - 07:38 AM

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


Blekinge Institute of Technology
Twitter @devmoon
Homepage http://devmoon.se
Stream http://twitch.tv/devmoon

#13 Acharis   Crossbones+   -  Reputation: 3673

Like
0Likes
Like

Posted 06 January 2014 - 08:51 AM

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.


Europe1300.eu - Historical Realistic Medieval Sim (RELEASED!)





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS