简体   繁体   English

Jint + XNA(C#)

[英]Jint + XNA (C#)

是否可以使用jint来操作使用XNA(C#)创建的3D环境,并为此环境添加功能(再次使用jint)?

As a contributor to Jint, I would recommend you Jint . 作为Jint的贡献者,我建议你使用Jint Jint makes it more simple than what Lua does. Jint使它比Lua更简单。 Moreover, I don't know if this is possible with Lua, but you can give it .NET objects and play with them in javascript (Jint stands for Javascript INTpreter). 此外,我不知道这是否可以用Lua,但你可以给它.NET对象并在javascript中使用它们(Jint代表Javascript INTpreter)。 You can also secure your application with Permissions Set. 您还可以使用权限集保护您的应用程序。 Here is the same code provided before with Jint : 以下是Jint之前提供的相同代码:

    class Program
{
    static void Main(string[] args)
    {
        Program p = new Program();
        p.Run();
    }

    private void Run()
    {
        JintEngine engine = new JintEngine();
        engine.SetFunction("GTest", new Jint.Delegates.Func<object, double>(LUA_GTest));
        engine.Run("GTest([['3,3']])");
    }

    private double LUA_GTest(object d)
    {
        Console.WriteLine("Got {0} - {1}", d.GetType().ToString(), d.ToString());
        while (d is ArrayList)
        {
            d = ((ArrayList)d)[0];
            Console.WriteLine("Got {0} - {1}", d.GetType().ToString(), d.ToString());
        }
        if (d is string)
        {
            d = double.Parse((string)d);
            Console.WriteLine("Got {0} - {1}", d.GetType().ToString(), d.ToString());
        }
        if (d is double)
            return (double)d * 2;
        return 0;
    }
}

Jint is an option, LUA is an option check out LuaForge Jint是一个选项,LUA是LuaForge的选项

LUA is a really fun and easy to use language, with nice support for cooperative multitasking (coroutines). LUA是一种非常有趣且易于使用的语言,对协作式多任务(协同程序)提供了很好的支持。 Its basic data type is a table (which is a cross between a dictionary and an array) which is very flexible and powerful. 它的基本数据类型是一个表(它是字典和数组之间的交叉),它非常灵活和强大。

Here's something I wrote up just now just to test it. 这是我刚刚写的东西,只是为了测试它。 I am registering a function for the script called GTest which maps to a C# method in my object called LUA_GTest . 我正在为名为GTest的脚本注册一个函数,该函数映射到我的对象中称为LUA_GTest的C#方法。 The method accepts a general object, and in the script I'm passing to it a table containing a table containing a string representing a double. 该方法接受一个通用对象,并在脚本中向其传递一个表,该表包含一个表,该表包含表示double的字符串。 In C# i'm unwrapping everything and returning a value based on the double value. 在C#中我打开所有内容并根据double值返回一个值。

class Program
{
    static void Main(string[] args)
    {
        Program p = new Program();
        p.Run();
    }

    private void Run()
    {
        Lua lua = new Lua();
        var methodInfo = typeof(Program).GetMethod("LUA_GTest", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
        lua.RegisterFunction("GTest", this, methodInfo);
        lua.DoString("GTest({{\"3.3\"}})");
    }

    private double LUA_GTest(object d)
    {
        Console.WriteLine("Got {0} - {1}", d.GetType().ToString(), d.ToString());
        while (d is LuaTable)
        {
            d = ((LuaTable)d)[1];
            Console.WriteLine("Got {0} - {1}", d.GetType().ToString(), d.ToString());
        }
        if (d is string)
        {
            d = double.Parse((string)d);
            Console.WriteLine("Got {0} - {1}", d.GetType().ToString(), d.ToString());
        }
        if (d is double)
            return (double)d * 2;
        return 0;
    }
}

Take a look at this SO question , considering how to choose a scripting platform for .Net. 考虑如何为.Net选择脚本平台,看看这个SO问题

In general, sure you can build a scripting engine into your XNA application. 通常,确保您可以在XNA应用程序中构建脚本引擎。 Using a scripting engine and providing hooks into your app is not much different than calling external assemblies through public interfaces. 使用脚本引擎并在应用程序中提供挂钩与通过公共接口调用外部程序集没有太大区别。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM