public static DocItem CreateDocumentation(ScriptBindings bindings)
        {
            DocItem doc = new DocItem(DocItemType.Table)
            {
            };
            var bi = bindings.bindItems.Values;

            foreach (var item in bi)
            {
                if (item is BindTable bTable)
                {
                    doc.SubDocs.Add(DocumentTable(bTable, "", 0));
                }
                else if (item is BindFunc func)
                {
                    doc.SubDocs.Add(DocumentFunction(func, ""));
                }
                else if (item is BindUserType bUserType)
                {
                    doc.SubDocs.Add(DocumentType(bUserType, "", 0));
                }
                else if (item is BindUserObject bUserObj)
                {
                    doc.SubDocs.Add(DocumentObject(bUserObj, "", 0));
                }
                else if (item is BindEnum bEnum)
                {
                    doc.SubDocs.Add(DocumentEnum(bEnum, ""));
                }
            }

            doc.Sort();

            return(doc);
        }
Beispiel #2
0
        private void bTest0_Click(object sender, EventArgs e)
        {
            string s = "function A() Test.MyTables.PrintPlusA('one', 'two') end " +
                       "function B() " +
                       "print(1)" +
                       "coroutine.yield()" +
                       "print(2)" +
                       "coroutine.yield()" +
                       "print(3)" +
                       "end " +
                       "RegisterCoroutine(A, 'A', true) " +
                       //"RegisterCoroutine(b, 'B', true) " +
                       "";

            bool         isCoroutine        = true;
            bool         autoResetCoroutine = true;
            HookStandard standard           = new HookStandard(
                new FuncStandard("A", FuncType.AutoCoroutine | FuncType.AllowAny),
                new FuncStandard("B", FuncType.AutoCoroutine | FuncType.AllowAnyCoroutine)
                );

            HookedScriptRunner hsr = new HookedScriptRunner(standard);


            ScriptBindings b = new ScriptBindings(this);

            b.HookDelegate("Test.YieldPls", (Func <int, string, WaitUntil>)AutoCoroutineTest, "", "");
            hsr.AddBindings(b);
            hsr["text"] = "test";
            hsr.LoadScript(s);
            hsr.LoadScript(s);
            hsr.LoadScript(s);
            hsr.LoadScript(s);
            hsr.LoadScript(s);
            hsr.LoadScript(s);
            hsr.RefreshLua();

            hsr.Execute("A");

            for (int j = 0; j < 30; j++)
            {
                Console.WriteLine($"==========C# {j + 1}");
                hsr.Execute("B");
            }



            //Script s = new Script();
            //s.Globals["PrintPlusA"]
            //var a = CallbackFunction.FromDelegate(s, (Action<string>)PrintPlusA);

            //a.
            //var b = CallbackFunction.FromDelegate(s, (Action<string, string>)PrintPlusA);
            //s.DoString(@"PrintPlusA(")

            //DynValue.NewCallbackFu(CallbackFunction)
            //DynValue.NewYieldReq()
            //Closure c = new Closure();
            //DynValue.FromObject(s.Globals["test"]).Function.GetUpvalue
        }
 public UserScriptRunner(ScriptBindings bindings = null)
 {
     Lua = new Script(CoreModules.Preset_HardSandbox | CoreModules.Coroutine | CoreModules.OS_Time);
     Lua.Globals["RegisterHook"]      = (Action <DynValue, string>)RegisterHook;
     Lua.Globals["RegisterCoroutine"] = (Action <DynValue, string, bool>)RegisterCoroutine;
     Lua.Globals["RemoveHook"]        = (Action <string>)RemoveHook;
     GlobalScriptBindings.Initialize(Lua);
     bindings?.Initialize(Lua);
 }
        public static DocItem CreateDocumentation(params Assembly[] assemblies)
        {
            var bindings = new ScriptBindings();

            bindings.BindAssembly(assemblies);

            DocItem doc = new DocItem(DocItemType.Table, null, "Root", "Root", "");
            var     bi  = bindings.bindItems.Values;

            foreach (var item in bi)
            {
                if (item is BindTable bTable)
                {
                    doc.SubDocs.Add(DocumentTable(bTable, "", 0));
                }
                else if (item is BindFunc func)
                {
                    doc.SubDocs.Add(DocumentFunction(func, ""));
                }
                else if (item is BindUserType bUserType)
                {
                    doc.SubDocs.Add(DocumentType(bUserType, "", 0));
                }
                else if (item is BindUserObject bUserObj)
                {
                    doc.SubDocs.Add(DocumentObject(bUserObj, "", 0));
                }
                else if (item is BindEnum bEnum)
                {
                    doc.SubDocs.Add(DocumentEnum(bEnum, ""));
                }
            }

            doc.Sort();

            return(doc);
        }
 public void AddBindings(ScriptBindings bindings)
 {
     bindings.Initialize(Lua);
 }