Пример #1
0
        public void AddMethod(String funcName, String[] args, ScriptCallbackCB callback, Object userdata)
        {
            ScriptVar funcVar = new ScriptVar(null, ScriptVar.Flags.Function | ScriptVar.Flags.Native);

            funcVar.SetCallback(callback, userdata);

            //do we have any arguments to create?
            if (args != null)
            {
                foreach (string arg in args)
                {
                    funcVar.AddChildNoDup(arg, null);
                }
            }

            Root.AddChild(funcName, funcVar);
        }
Пример #2
0
        public void AddMethod(String funcProto, ScriptCallbackCB callback, Object userdata)
        {
            ScriptLex oldLex = _currentLexer;

            using (_currentLexer = new ScriptLex(funcProto))
            {
                ScriptVar baseVar = Root;

                _currentLexer.Match(ScriptLex.LexTypes.RFunction);
                String funcName = _currentLexer.TokenString;
                _currentLexer.Match(ScriptLex.LexTypes.Id);

                while (_currentLexer.TokenType == (ScriptLex.LexTypes) '.')
                {
                    _currentLexer.Match((ScriptLex.LexTypes) '.');
                    ScriptVarLink link = baseVar.FindChild(funcName);

                    if (link == null)
                    {
                        link = baseVar.AddChild(funcName, new ScriptVar(null, ScriptVar.Flags.Object));
                    }

                    baseVar  = link.Var;
                    funcName = _currentLexer.TokenString;
                    _currentLexer.Match(ScriptLex.LexTypes.Id);
                }

                ScriptVar funcVar = new ScriptVar(null, ScriptVar.Flags.Function | ScriptVar.Flags.Native);
                funcVar.SetCallback(callback, userdata);

                ParseFunctionArguments(funcVar);

                baseVar.AddChild(funcName, funcVar);
            }

            _currentLexer = oldLex;
        }
Пример #3
0
        public void AddMethod(String[] ns, String funcName, String[] args, ScriptCallbackCB callback, Object userdata)
        {
            String    fName   = funcName;
            ScriptVar baseVar = Root;

            if (ns != null)
            {
                int x = 0;
                for (; x < ns.Length; x++)
                {
                    ScriptVarLink link = baseVar.FindChild(ns[x]);

                    if (link == null)
                    {
                        link = baseVar.AddChild(ns[x], new ScriptVar(null, ScriptVar.Flags.Object));
                    }

                    baseVar = link.Var;
                }
            }


            ScriptVar funcVar = new ScriptVar(null, ScriptVar.Flags.Function | ScriptVar.Flags.Native);

            funcVar.SetCallback(callback, userdata);

            //do we have any arguments to create?
            if (args != null)
            {
                foreach (string arg in args)
                {
                    funcVar.AddChildNoDup(arg, null);
                }
            }

            baseVar.AddChild(fName, funcVar);
        }
Пример #4
0
        public void AddNative(string funcDesc, ScriptCallbackCB callbackCB, object userData)
        {
            var oldLex = currentLexer;

            currentLexer = new ScriptLex(funcDesc);

            var baseVar = Root;

            currentLexer.Match(ScriptLex.LexTypes.RFunction);
            var funcName = currentLexer.TokenString;

            currentLexer.Match(ScriptLex.LexTypes.Id);

            while (currentLexer.TokenType == (ScriptLex.LexTypes) '.')
            {
                currentLexer.Match((ScriptLex.LexTypes) '.');

                var link = baseVar.FindChild(funcName);
                if (link == null)
                {
                    link = baseVar.AddChild(funcName, new ScriptVar(null, ScriptVar.Flags.Object));
                }
                baseVar  = link.Var;
                funcName = currentLexer.TokenString;
                currentLexer.Match(ScriptLex.LexTypes.Id);
            }

            var funcVar = new ScriptVar(null, ScriptVar.Flags.Function | ScriptVar.Flags.Native);

            funcVar.SetCallback(callbackCB, userData);
            ParseFunctionArguments(funcVar);

            currentLexer = oldLex;

            baseVar.AddChild(funcName, funcVar);
        }