0

I used Visual Studio 2019 to build a form of some sort that I want to use to execute scripts in a TextBox within that textbox, so if I do print("Hello"); the next line will be hello. I use FastColoredTextBox to do that and I noticed it has a language property that I already set to Lua. How can I actually execute commands within that textbox tho?

I appreciate all your help :)

0

1 Answer 1

1

You can install DynamicLua package to compile and run Lua code in C#.

For example, I assume you have a fastColoredTextBox1 on your form and a button to toolStripButton1 to run the code, then you can add the following code:

private void Form1_Load(object sender, EventArgs e)
{
    this.fastColoredTextBox1.Language = FastColoredTextBoxNS.Language.Lua;
    this.fastColoredTextBox1.Text= "function echo(s) return s end" + "\n" +
        "return echo(\"Hello!\")";
}

private void toolStripButton1_Click(object sender, EventArgs e)
{
    dynamic lua = new DynamicLua.DynamicLua();
    var result = lua(fastColoredTextBox1.Text);
    MessageBox.Show($"{result}"); 
}

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.