// Arguments in C# methods are optional. // To elaborate, a Lua script can execute the below function // with two arguments, despite the fact that there is only one // C# argument. This is because we must check for the existance // of the Lua arguments within this C# method. So if Lua // executes this method without argument 1 of type string and // argument 2 of type function, a Lua error is emitted to VM. // If you choose to add arguments to a C# function, the GLua // type marshals will attempt to cast the Lua arguments to // its equivalent C# type. If a cast fails, the C# argument uses // defaults. private static void SecretPhrase() { int callback = -1; Console.WriteLine("Finding the secret phrase..."); // This will freeze the server for five second because we aren't asynchronous System.Threading.Thread.Sleep(5000); // Push the callback function to the stack Lua.Push(2); // Push argument 1 to the stack Lua.Push("rusty bullet hole"); // Create the Lua reference after all arguments are passed callback = Lua.ReferenceCreate(); // Push our completed reference back to the stack Lua.ReferencePush(callback); // Call the callback function with our secret phrase as argument 1 Lua.Call(1, 0); }