moonsharp icon indicating copy to clipboard operation
moonsharp copied to clipboard

Lowercase Descriptors

Open wledfor2 opened this issue 8 years ago • 2 comments

As it stands, the following method:

public void WriteLine(string message) { //... }

Can only be accessed in Lua under the identifiers WriteLine, and writeLine, but not writeline.

I would like to request the additional feature of allowing the method to be accessed with the identifier writeline; in other words, allow case insensitive identifiers for userdata.

The rationale for this is that most if not all built in Lua modules use fully lowercase function names. This would be useful to allow for a more consistent style in projects that use MoonSharp. I think having a consistent style throughout your Lua code would help with readability.

Example:

using System;
using MoonSharp.Interpreter;

using static System.Console;

namespace Example {

	public class TestType {

		public void Write(string s) => Console.Write(s);
		public void WriteLine(string s) => Console.WriteLine(s);

	}

	public class Program {

		public static void Main(string[] args) {

			try {

				Script script = new Script();

				UserData.RegisterType<TestType>();
				script.Globals["test"] = UserData.Create(new TestType());
				script.DoString(@"

					-- these work
					test.write(""hello"")
					test.WriteLine(""hello"")
					test.writeLine(""hello"")

					-- throws exception: cannot access field writeline of userdata<TestType>
					test.writeline(""hello"")

				");

			} catch (InterpreterException e) {

				Error.WriteLine(e.DecoratedMessage);

			}

		}

	}

}

wledfor2 avatar Oct 06 '17 20:10 wledfor2

Fuzzy matching methods extendable flag/options from @wledfor2 merged, this should be easily resolvable.

LimpingNinja avatar Jan 15 '20 16:01 LimpingNinja

I will PR this myself most likely, I would like to setup some better unit tests for symbol fuzzy-matching first.

wledfor2 avatar Jan 15 '20 23:01 wledfor2