public async Task <object> CallFunctionAsync(string name, list paramList) { Function userfunc = null; IScriptContextFunction scriptCtxtFunction = null; if ( !m_userFunctions.TryGetValue(name, out userfunc) && !m_scriptContextFunctions.TryGetValue(name, out scriptCtxtFunction) ) { throw new ScriptException("Function not found: " + name); } if (userfunc != null) { if (paramList.Count != userfunc.ParamNames.Count) { throw new ScriptException ( "Function " + name + " takes " + userfunc.ParamNames.Count + " paramters, " + "not " + paramList.Count + ": " + string.Join(", ", userfunc.ParamNames) ); } using (var smacker = new SymbolSmacker(m_symbols)) using (var stacker = new SymbolStacker(m_symbols)) { for (int p = 0; p < userfunc.ParamNames.Count; ++p) { m_symbols.Set(userfunc.ParamNames[p], paramList[p]); } object returnValue = await ProcessAsync ( userfunc.StartIndex, userfunc.EndIndex, new ProcessOutcome(), m_tempIndentLevel, m_tempCallDepth + 1 ).ConfigureAwait(false); return(returnValue); } } else { object returnValue = await scriptCtxtFunction.CallAsync ( m_scriptContext, paramList ).ConfigureAwait(false); return(returnValue); } }
public void TestSymbolSmacker() { var table = new SymbolTable(); table.Set("foo", "bar"); using (SymbolStacker stacker1 = new SymbolStacker(table)) { table.Set("blet", "monkey"); using (SymbolSmacker smacker = new SymbolSmacker(table)) using (SymbolStacker stacker2 = new SymbolStacker(table)) { Assert.IsTrue(table.Contains("foo")); Assert.IsFalse(table.Contains("blet")); table.Set("something", "else"); } Assert.IsTrue(table.Contains("blet")); Assert.IsFalse(table.Contains("something")); } Assert.IsTrue(table.Contains("foo")); Assert.IsFalse(table.Contains("blet")); Assert.IsFalse(table.Contains("something")); }