private static void RegisterLuaCallFunc() { var reader = ScutReader.GetIntance(); Type readerType = reader.GetType(); _luaContext.RegisterFunc("ScutReader_getResult", reader, readerType.GetMethod("getResult")); _luaContext.RegisterFunc("ScutReader_readAction", reader, readerType.GetMethod("readAction")); _luaContext.RegisterFunc("ScutReader_readErrorCode", reader, readerType.GetMethod("readErrorCode")); _luaContext.RegisterFunc("ScutReader_readErrorMsg", reader, readerType.GetMethod("readErrorMsg")); _luaContext.RegisterFunc("ScutReader_getWORD", reader, readerType.GetMethod("getWORD")); _luaContext.RegisterFunc("ScutReader_getInt", reader, readerType.GetMethod("getInt")); _luaContext.RegisterFunc("ScutReader_getByte", reader, readerType.GetMethod("getByte")); _luaContext.RegisterFunc("ScutReader_getLong", reader, readerType.GetMethod("getLong")); _luaContext.RegisterFunc("ScutReader_getDouble", reader, readerType.GetMethod("getDouble")); _luaContext.RegisterFunc("ScutReader_readString", reader, readerType.GetMethod("readString")); _luaContext.RegisterFunc("ScutReader_recordBegin", reader, readerType.GetMethod("recordBegin")); _luaContext.RegisterFunc("ScutReader_recordEnd", reader, readerType.GetMethod("recordEnd")); var writer = ScutWriter.getInstance(); Type writerType = writer.GetType(); _luaContext.RegisterFunc("ScutWriter_writeString", writer, writerType.GetMethod("writeString")); _luaContext.RegisterFunc("ScutWriter_writeInt32", writer, writerType.GetMethod("writeInt32")); _luaContext.RegisterFunc("ScutWriter_writeWord", writer, writerType.GetMethod("writeWord")); _luaContext.RegisterFunc("ScutWriter_writeHead", writer, writerType.GetMethod("writeHead")); }
private void btnLuaRunPath_Click(object sender, EventArgs e) { try { string host = txtHost.Text; int port = txtPort.Text.ToInt(); int actionId = txtAction.Text.ToInt(); string pwd = txtPwd.Text.Trim(); _token.GameType = txtGameType.Text.ToInt(); _token.ServerID = txtServerID.Text.ToInt(); _token.RetailID = txtRetailID.Text.Trim(); _token.Pid = txtPid.Text.Trim(); _token.Pwd = EncodePwdAndUrlEncode(pwd); SetConfig(host, port, actionId, _token, pwd); string funName = string.Format("Action{0}", actionId); ScutWriter.getInstance().writeHead(_token.Sid, _token.Uid.ToInt()); ScutWriter.getInstance().writeInt32("ActionId", actionId); if (!LuaRuntime.GetContext().TryCall <Action <UserToken> >(funName, _token)) { _responseLog.WriteFormatLine("请求出错:The {0} function is not exist in lua file.", funName); } var sendData = ScutWriter.generatePostData(); TcpRequest.Instance().Send(host, port, sendData, null); ScutWriter.resetData(); } catch (Exception ex) { _responseLog.WriteFormatLine("请求出错:{0}", ex); } finally { ResponseReflesh(); } }