Help with NLua, and implementing a scripting language to my game

So I’m trying to use NLua to add custom effects to my game, but I’m having problems with the “RegisterFunction”. it wont register properly, theres not errors but its not working

public void RegisterFunctions() {
		lua.RegisterFunction("debug", this, GetType().GetMethod("debug"));

	public void StartLua(){
		ABtype type = new ABtype();
		type.RegisterFunctions ();
		type.LoadFile (Application.streamingAssetsPath + "/ability.lua");
		type.DoFile (Application.streamingAssetsPath + "/ability.lua");

	void debug (string x) {
		Debug.Log (x);

some reason that above code is not working, here is the lua file

x = "Hello World"
function Debug(x)
	print (x)
end function

I haven’t used NLua yet but there are some things that seems strange to me.

First of all you registrating your debug method with the global name “debug”. However you don’t use that method in your lua code.

Second your lua code simply does nothing. You set the global variable “x” to “Hello World” and define a global function named “Debug”. You never execute any method inside your lua code. Keep in mind that lua is case sensitive, so “debug” and “Debug” are two seperate things. Also keep in mind your Debug method takes a parameter named “x”, but that parameter has nothing to do with your globally defined variable “x” as function parameters are local to the function.

Finally to end a function definition in lua you just have to use “end”, not “end function”. LUA is not Visual Basic ^^.

Try something like that:

x = "Hello World"

function Debug(x)

debug(x)  -- calling your registrated native C# method

Debug("Testing Debug function")  -- calling the above defined Debug method

print in lua will output to command line console, but it may not shows in the c# Output window.
You should call Console.WriteLine() to make sure it shows into the Output Window