public object _ps(INakoFuncCallInfo info) { NakoVarArray result = new NakoVarArray(); foreach(System.Diagnostics.Process p in System.Diagnostics.Process.GetProcesses()){ try{ result.SetValue(result.Count,p.ProcessName); }catch(Exception e){ } } return result; }
private static NakoVarArray ArrayToNakoVarArray(object obj) { NakoVarArray a = new NakoVarArray(); if(obj is IDictionary<string,object>){ Dictionary<string,object> dic = (Dictionary<string,object>)obj; foreach (KeyValuePair<string, object> item in dic) { if((item.Value is IDictionary<string,object>) || (item.Value is object[]) || (item.Value is IList<object>)){ a.SetValueFromKey(item.Key,ArrayToNakoVarArray(item.Value)); }else{ a.SetValueFromKey(item.Key,item.Value); } } }else if(obj is object[]){ object[] li = (object[])obj; foreach(object item in li) { if((item is IDictionary<string,object>) || (item is object[]) || (item is IList<object>)){ a.SetValue(a.Count,ArrayToNakoVarArray(item)); }else{ a.SetValue(a.Count,item); } } }else if(obj is IList<object>){ List<object> li = (List<object>)obj; foreach(object item in li) { if((item is IDictionary<string,object>) || (item is object[]) || (item is IList<object>)){ a.SetValue(a.Count,ArrayToNakoVarArray(item)); }else{ a.SetValue(a.Count,item); } } } return a; }
public Object _matchAll(INakoFuncCallInfo info) { string s = info.StackPopAsString(); string pattern = info.StackPopAsString(); m = Regex.Match(s,pattern); NakoVarArray res = info.CreateArray(); int index = 0; NakoVarArray groups = new NakoVarArray(); // NakoVariable ret = new NakoVariable(); while(m.Success){ res.SetValue(index,m.Value); NakoVarArray subgroups = new NakoVarArray(); for (int i = 0; i < m.Groups.Count; i++) { subgroups.SetValue(i,m.Groups[i].Value); } groups.Add(subgroups); // for(int i = 0;i < m.Groups.Count;i++){ // groups.SetValue(i,m.Groups[i].Value); // } // ret.Type = NakoVarType.Array; // ret.Body = groups; index++; m = m.NextMatch(); } info.SetVariableValue("抽出文字列", groups); return res; }