【问题标题】:How to run a Lua script within a Windows Forms TextBox如何在 Windows 窗体文本框中运行 Lua 脚本
【发布时间】:2020-06-04 10:39:04
【问题描述】:

我使用 Visual Studio 2019 构建了某种形式,我想用它来执行该文本框中 TextBox 中的脚本,所以如果我这样做 print("Hello"); ,下一行将是你好。 我使用FastColoredTextBox 来做到这一点,我注意到它有一个我已经设置为 Lua 的语言属性。我如何才能在该文本框中实际执行命令?

感谢您的帮助:)

【问题讨论】:

    标签: c# .net winforms lua


    【解决方案1】:

    你可以安装DynamicLua包来编译和运行C#中的Lua代码。

    例如,我假设您的表单上有一个fastColoredTextBox1 和一个指向toolStripButton1 的按钮来运行代码,那么您可以添加以下代码:

    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}"); 
    }
    

    【讨论】:

      猜你喜欢
      • 2016-08-10
      • 2016-06-19
      • 2016-03-29
      • 2018-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-28
      • 1970-01-01
      相关资源
      最近更新 更多