Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I've been messing with LUA in C# lately, I've managed to do quite a bit with it. The only thing I haven't figured out is how to process an event. For example, if I created a function that dynamically creates a button:


C#
Button cmdName = new Button();
cmdName+= new System.EventHandler(cmdName.Click);

private void cmdName_Click(object sender, System.EventArgs e) {
   // Do something
}


How would I do that with LUA via C# code? I hope this makes sense.. Just take note that I know how to already setup lua in C#. I just need to know how to handle events, so I would need lua code (not following the lua syntax properly I know) like:

PHP
AddButton(posx, posy, "Something", ClickEventName)

function ClickEventName
  ShowMsg("Clicked on the button!")
end
Posted
Comments
BillWoodruff 8-Jan-12 6:22am    
Your C# code example's a bit off: use either:

cmdName.Click +=new EventHandler(cmdName_Click);

or, with later versions of .NET:

cmdName.Click += cmdName_Click;

or (Lambda style):

cmdName.Click += (o, args) =>
{
// do something
};

Not familiar with Lua, sorry.

best, Bill

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900