private object _append(INakoFuncCallInfo info) { object ary = info.StackPop(); // 参照渡しなので変数への参照が得られる object s = info.StackPop(); if (!(ary is NakoVariable)) { throw new NakoPluginRuntimeException("『追加』の引数がvariableではありません"); } NakoVariable ary_link = (NakoVariable)ary; if (ary_link.Body is NakoVarArray) { NakoVarArray arr = (NakoVarArray)ary_link.Body; NakoVariable new_item = new NakoVariable(); new_item.SetBodyAutoType(s); arr.Add(new_item); }else if(ary_link.Body is string && (string)ary_link.Body==""){ NakoVarArray arr = new NakoVarArray(); NakoVariable new_item = new NakoVariable(); new_item.SetBodyAutoType(s); arr.Add(new_item); ary_link.SetBody(arr,NakoVarType.Array); } // 結果をセット return null; }
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 object _insertArray(INakoFuncCallInfo info) { object obj_base = info.StackPop(); // 参照渡しなので変数への参照が得られる int i = (int)info.StackPopAsInt(); object obj_insert = info.StackPop(); if (!(obj_base is NakoVariable)) { throw new NakoPluginRuntimeException("『配列一括挿入』の元配列がvariableではありません"); } NakoVarArray array_insert = new NakoVarArray(); if (obj_insert is NakoVariable) { NakoVariable var_insert = (NakoVariable)obj_insert; if(var_insert.Body is NakoVarArray){ array_insert = (NakoVarArray)var_insert.Body; } }else if(obj_insert is string){ array_insert.SetValuesFromString((string)obj_insert); }else{ throw new NakoPluginRuntimeException("『配列一括挿入』の挿入配列がvariableではありません"); } NakoVariable var_base = (NakoVariable)obj_base; if(var_base.Body is NakoVarArray){ NakoVarArray array_base = (NakoVarArray)var_base.Body; while(array_insert.Count>0){ NakoVariable variable = array_insert.Pop(); array_base.Insert(i,variable); } } return null; }
void SetCommandLine(NakoInterpreter runner) { NakoVarArray a = new NakoVarArray(); a.SetValuesFromStrings(this.args); int i = runner.globalVar.GetIndex("コマンドライン"); runner.globalVar.SetValue(i, a); }
protected static object NakoVarArrayToArray(NakoVarArray array) { bool is_dictionary = false; if(array.Count>0){ NakoVariable check = array.GetVar(0); if(check.key!=null){ is_dictionary = true; } if(is_dictionary){ var result = new Dictionary<string,object>(); foreach(NakoVariable variable in array){ if(variable.Body is NakoVarArray){ result.Add(variable.key,NakoVarArrayToArray((NakoVarArray)variable.Body)); }else{ result.Add(variable.key,variable.Body); } } return result; }else{ var result = new List<object>(); foreach(NakoVariable variable in array){ if(variable.Body is NakoVarArray){ result.Add(NakoVarArrayToArray((NakoVarArray)variable.Body)); }else{ result.Add(variable.Body); } } return result; } } return null; }
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 _getHeaderHash(INakoFuncCallInfo info) { string url = info.StackPopAsString(); WebRequest req = WebRequest.Create(url); req.Method = "HEAD"; HttpWebResponse response = (HttpWebResponse) req.GetResponse(); NakoVarArray returnArray = new NakoVarArray(); foreach(var key in response.Headers.Keys){ string[] values = response.Headers.GetValues((string)key); NakoVarArray arrays = new NakoVarArray(); arrays.SetValuesFromStrings(values); returnArray.SetValueFromKey((string)key,arrays); } returnArray.SetValueFromKey((string)"HTTP.Response",response.StatusCode.GetHashCode().ToString()); returnArray.SetValueFromKey((string)"Status",response.StatusCode.GetHashCode().ToString()); return returnArray; }
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; }
// --- 値を作成する /// <summary> /// 配列変数を生成して返す /// </summary> /// <returns></returns> public NakoVarArray CreateArray() { NakoVarArray v = new NakoVarArray(); return v; }