/// <summary> /// To test the mono interface, call following from any NPL script. /// /// NPL.activate("NPLMonoInterface.dll/NPLMonoInterface.cs", {data="test NPLMonoInterface"}); /// </summary> public static void activate(ref int nType, ref IntPtr npl_runtime_state) { // example 1: getting input message and write to application log string msg = NPL.GetCurrentMsg(npl_runtime_state); ParaGlobal.applog("Example 1: " + msg); // example 2: activate another file NPL.activate(npl_runtime_state, "NPLMonoInterface.dll/ParaMono.NPLMonoInterface.cs", "msg={example=2}"); // example 3: generate new message using NPLWriter:to generate the string : msg={name=1,2,{"3"="4",},}; NPLWriter writer = new NPLWriter(); writer.WriteName("msg"); writer.BeginTable(); writer.WriteName("name"); writer.WriteValue(1); writer.WriteValue(2); writer.BeginTable(); writer.WriteName("3", true); writer.WriteValue("4"); writer.EndTable(); writer.EndTable(); writer.WriteParamDelimiter(); ParaGlobal.applog("Example 3: " + writer.ToString()); // Example 4: Create NPLTable and serialize to string NPLObjectProxy msg1 = new NPLObjectProxy(); msg1["nid"].Assign(10); msg1["name"].Assign("value"); msg1["tab"]["name1"].Assign("value1"); StringBuilder output = new StringBuilder(); NPLHelper.NPLTableToString(null, msg1, output); ParaGlobal.applog("Example 4: " + output.ToString()); // Example 5: deserialize NPLTable from string. NPLObjectProxy tabMsg = NPLHelper.StringToNPLTable("{nid=10, u_nid=1, [\"1a\"]=2, name=\"value\", tab={name1=\"value1\"}}"); NPLHelper.NPLTableToString(null, tabMsg, output); ParaGlobal.applog("Example 5: " + output.ToString()); ParaGlobal.applog(String.Format("Example 5 checking: {0}==10, {1}==value, {2}==value1", (double)tabMsg["nid"], (string)tabMsg["name"], (string)(tabMsg["tab"]["name1"]))); // Example 6: parse a activation incoming message. tabMsg = NPLHelper.MsgStringToNPLTable(msg); NPLHelper.NPLTableToString(null, tabMsg, output); ParaGlobal.applog("Example 6: " + output.ToString()); Console.WriteLine("hello world!"); }
public void SetField(int nIndex, NPLObjectProxy obj) { if (obj != null) m_index_fields[nIndex] = obj; else m_index_fields.Remove(nIndex); }
/** Set the field. * @param sName: the field name * @param pObject: if NULL, it will remove the field, as if nil in lua. */ public void SetField(string sName, NPLObjectProxy obj) { if (obj != null) m_fields[sName] = obj; else m_fields.Remove(sName); }
public NPLObjectProxy CreateGetField(int nIndex) { if(m_index_fields.ContainsKey(nIndex)) { return m_index_fields[nIndex]; } else { NPLObjectProxy obj = new NPLObjectProxy(); m_index_fields.Add(nIndex, obj); return obj; } }
/** create or get a field. It may return null proxy */ public NPLObjectProxy CreateGetField(string sName) { if(m_fields.ContainsKey(sName)) { return m_fields[sName]; } else { NPLObjectProxy obj = new NPLObjectProxy(); m_fields.Add(sName, obj); return obj; } }
public void Assign(NPLObjectProxy value) { m_ptr = value.m_ptr; }