From d0a6e11a0c8bdd506e7b15ca92cb6ba3360413cd Mon Sep 17 00:00:00 2001 From: Carlo Date: Thu, 22 Aug 2024 11:18:07 +0200 Subject: [PATCH] - inserita EntExecProcess --- Supervisor/LUA/Lua_General.vb | 768 +++++++++++++++++----------------- 1 file changed, 385 insertions(+), 383 deletions(-) diff --git a/Supervisor/LUA/Lua_General.vb b/Supervisor/LUA/Lua_General.vb index 300eb53..d0d72af 100644 --- a/Supervisor/LUA/Lua_General.vb +++ b/Supervisor/LUA/Lua_General.vb @@ -1,39 +1,40 @@ -Imports KeraLua -Imports StackExchange.Redis -Imports System.IO - -Public Module Lua_General - - ' Lock per scrittura file di log - Private m_Lock_OutLog As New Object - - Private m_sLogPath As String - Friend Sub SetLogPath(sPath As String) - m_sLogPath = sPath - End Sub - - ' da eliminare quando arriva funzione di libreria!! - Public Function EgtOutLog(sLogMsg As String) As Boolean - SyncLock (m_Lock_OutLog) - Using LogStreamWriter As StreamWriter = File.AppendText(m_sLogPath) - LogStreamWriter.WriteLine(DateTime.Now.ToLongTimeString() & " " & sLogMsg) - End Using - End SyncLock - Return True - End Function - - Friend func_EntIs64bit As LuaFunction = AddressOf Lua_EntIs64bit - Friend func_EntOutLog As LuaFunction = AddressOf Lua_EntOutLog - Friend func_EntExistsDirectory As LuaFunction = AddressOf Lua_EntExistsDirectory - Friend func_EntCopyFile As LuaFunction = AddressOf Lua_EntCopyFile - Friend func_EntGetIniFile As LuaFunction = AddressOf Lua_EntGetIniFile - Friend func_EntGetDataDir As LuaFunction = AddressOf Lua_EntGetDataDir - Friend func_EntGetNumberFromIni As LuaFunction = AddressOf Lua_EntGetNumberFromIni - Friend func_EntGetStringFromIni As LuaFunction = AddressOf Lua_EntGetStringFromIni - Friend func_EntWriteStringToIni As LuaFunction = AddressOf Lua_EntWriteStringToIni - Friend func_RdsStringGet As LuaFunction = AddressOf Lua_RdsStringGet - Friend func_RdsStringSetAsync As LuaFunction = AddressOf Lua_RdsStringSetAsync - Friend func_RdsPublishAsync As LuaFunction = AddressOf Lua_RdsPublishAsync +Imports KeraLua +Imports StackExchange.Redis +Imports System.IO + +Public Module Lua_General + + ' Lock per scrittura file di log + Private m_Lock_OutLog As New Object + + Private m_sLogPath As String + Friend Sub SetLogPath(sPath As String) + m_sLogPath = sPath + End Sub + + ' da eliminare quando arriva funzione di libreria!! + Public Function EgtOutLog(sLogMsg As String) As Boolean + SyncLock (m_Lock_OutLog) + Using LogStreamWriter As StreamWriter = File.AppendText(m_sLogPath) + LogStreamWriter.WriteLine(DateTime.Now.ToLongTimeString() & " " & sLogMsg) + End Using + End SyncLock + Return True + End Function + + Friend func_EntIs64bit As LuaFunction = AddressOf Lua_EntIs64bit + Friend func_EntOutLog As LuaFunction = AddressOf Lua_EntOutLog + Friend func_EntExistsDirectory As LuaFunction = AddressOf Lua_EntExistsDirectory + Friend func_EntCopyFile As LuaFunction = AddressOf Lua_EntCopyFile + Friend func_EntGetIniFile As LuaFunction = AddressOf Lua_EntGetIniFile + Friend func_EntGetDataDir As LuaFunction = AddressOf Lua_EntGetDataDir + Friend func_EntGetNumberFromIni As LuaFunction = AddressOf Lua_EntGetNumberFromIni + Friend func_EntGetStringFromIni As LuaFunction = AddressOf Lua_EntGetStringFromIni + Friend func_EntWriteStringToIni As LuaFunction = AddressOf Lua_EntWriteStringToIni + Friend func_EntExecProcess As LuaFunction = AddressOf Lua_ExecProcess + Friend func_RdsStringGet As LuaFunction = AddressOf Lua_RdsStringGet + Friend func_RdsStringSetAsync As LuaFunction = AddressOf Lua_RdsStringSetAsync + Friend func_RdsPublishAsync As LuaFunction = AddressOf Lua_RdsPublishAsync Friend func_ComReadShortVar As LuaFunction = AddressOf Lua_ComReadShortVar Friend func_ComWriteShortVar As LuaFunction = AddressOf Lua_ComWriteShortVar Friend func_ComReadDoubleVar As LuaFunction = AddressOf Lua_ComReadDoubleVar @@ -47,350 +48,351 @@ Public Module Lua_General Return 1 End Function - Private Function Lua_EntOutLog(ByVal p As IntPtr) As Integer - Dim state = Lua.FromIntPtr(p) - ' 1 o 2 parametri : stringa da emettere [, DebugLevel = 0] - Dim sLogMsg As String = "" - Dim nDebugLevel As Integer = 0 - LuaCheckParam(state, 1, sLogMsg) - LuaGetParam(state, 2, nDebugLevel) - LuaClearStack(state) - ' accodo il messaggio nel file di log - EgtOutLog(sLogMsg) - ' non c'è risultato - Return 0 - End Function - - Private Function Lua_EntExistsDirectory(ByVal p As IntPtr) As Integer - Dim state = Lua.FromIntPtr(p) - ' 1 parametro : sDir - Dim sDirectory As String = "" - LuaCheckParam(state, 1, sDirectory) - LuaClearStack(state) - Dim bResult As Boolean - Try - ' verifico esistenza direttorio - bResult = Directory.Exists(sDirectory) - Catch ex As Exception - bResult = False - EgtOutLog("Lua_EntExistsDirectory on " & sDirectory & " failed! " & ex.Message) - End Try - ' restituisco il risultato - LuaSetParam(state, bResult) - Return 1 - End Function - - Private Function Lua_EntCopyFile(ByVal p As IntPtr) As Integer - Dim state = Lua.FromIntPtr(p) - ' 2 parametri : sFile, sNewFile - Dim sSourcePath As String = "" - Dim sDestinationPath As String = "" - LuaCheckParam(state, 1, sSourcePath) - LuaCheckParam(state, 2, sDestinationPath) - LuaClearStack(state) - Dim bResult As Boolean - Try - ' copio il file - File.Copy(sSourcePath, sDestinationPath, True) - bResult = True - Catch ex As Exception - bResult = False - EgtOutLog("Lua_EntCopyFile from " & sSourcePath & " to " & sDestinationPath & " failed! " & ex.Message) - End Try - ' restituisco il risultato - LuaSetParam(state, bResult) - Return 1 - End Function - - Private Function Lua_EntGetIniFile(ByVal p As IntPtr) As Integer - Dim state = Lua.FromIntPtr(p) - ' restituisco il risultato - LuaSetParam(state, IniFile.sPath) - Return 1 - End Function - - Private Function Lua_EntGetDataDir(ByVal p As IntPtr) As Integer - Dim state = Lua.FromIntPtr(p) - ' restituisco il risultato - LuaSetParam(state, Map.refMainWindowVM.MainWindowM.sDataRoot) - Return 1 - End Function - - Private Function Lua_EntGetNumberFromIni(ByVal p As IntPtr) As Integer - Dim state = Lua.FromIntPtr(p) - ' 4 parametri: sSec, sKey, dDef, sIniFile - Dim sSec As String = "" - Dim sKey As String = "" - Dim dDef As Integer = 0 - Dim sIniFile As String = "" - LuaCheckParam(state, 1, sSec) - LuaCheckParam(state, 2, sKey) - LuaCheckParam(state, 3, dDef) - LuaCheckParam(state, 4, sIniFile) - LuaClearStack(state) - Dim nResult As Integer = GetPrivateProfileInt(sSec, sKey, dDef, sIniFile) - ' restituisco il risultato - LuaSetParam(state, nResult) - Return 1 - End Function - - Private Function Lua_EntGetStringFromIni(ByVal p As IntPtr) As Integer - Dim state = Lua.FromIntPtr(p) - ' 4 parametri: sSec, sKey, sDef, sIniFile - Dim sSec As String = "" - Dim sKey As String = "" - Dim sDef As String = 0 - Dim sIniFile As String = "" - LuaCheckParam(state, 1, sSec) - LuaCheckParam(state, 2, sKey) - LuaCheckParam(state, 3, sDef) - LuaCheckParam(state, 4, sIniFile) - LuaClearStack(state) - Dim sResult As String = "" - GetPrivateProfileString(sSec, sKey, sDef, sResult, sIniFile) - ' restituisco il risultato - LuaSetParam(state, sResult) - Return 1 - End Function - - Private Function Lua_EntWriteStringToIni(ByVal p As IntPtr) As Integer - Dim state = Lua.FromIntPtr(p) - ' 4 parametri: sSec, sKey, sVal, sIniFile - Dim sSec As String = "" - Dim sKey As String = "" - Dim sVal As Integer = 0 - Dim sIniFile As String = "" - LuaCheckParam(state, 1, sSec) - LuaCheckParam(state, 2, sKey) - LuaCheckParam(state, 3, sVal) - LuaCheckParam(state, 4, sIniFile) - LuaClearStack(state) - Dim bResult As Boolean = WritePrivateProfileString(sSec, sKey, sVal, sIniFile) - ' restituisco il risultato - LuaSetParam(state, bResult) - Return 1 - End Function - - Private Function Lua_RdsStringGet(ByVal p As IntPtr) As Integer - Dim state = Lua.FromIntPtr(p) - If IsNothing(Map.refMainWindowVM.RedisManager) OrElse IsNothing(Map.refMainWindowVM.RedisManager.Subscriber) Then - EgtOutLog("Error! Trying to get string from a non existent redis!") - LuaSetParam(state) - Return 1 - End If - ' 1 parametro: sKey - Dim sKey As String = "" - LuaCheckParam(state, 1, sKey) - LuaClearStack(state) - Dim Result As RedisValue - Result = Map.refMainWindowVM.RedisManager.RedisDb.StringGet(sKey) - ' restituisco il risultato - LuaSetParam(state, Result) - Return 1 - End Function - - Private Function Lua_RdsStringSetAsync(ByVal p As IntPtr) As Integer - If IsNothing(Map.refMainWindowVM.RedisManager) OrElse IsNothing(Map.refMainWindowVM.RedisManager.Subscriber) Then - EgtOutLog("Error! Trying to set string on a non existent redis!") - Return 0 - End If - Dim state = Lua.FromIntPtr(p) - ' 2 parametri: sKey, sVal - Dim sKey As String = "" - Dim sVal As String = 0 - LuaCheckParam(state, 1, sKey) - LuaCheckParam(state, 2, sVal) - LuaClearStack(state) - Map.refMainWindowVM.RedisManager.RedisDb.StringSetAsync(sKey, sVal) - Return 0 - End Function - - Private Function Lua_RdsPublishAsync(ByVal p As IntPtr) As Integer - If IsNothing(Map.refMainWindowVM.RedisManager) OrElse IsNothing(Map.refMainWindowVM.RedisManager.Subscriber) Then - EgtOutLog("Error! Trying to publish on a non existent redis!") - Return 0 - End If - Dim state = Lua.FromIntPtr(p) - ' 2 parametri: sKey, sVal - Dim sChannel As String = "" - Dim sMessage As String = 0 - LuaCheckParam(state, 1, sChannel) - LuaCheckParam(state, 2, sMessage) - LuaClearStack(state) - Map.refMainWindowVM.RedisManager.Subscriber.PublishAsync(sChannel, sMessage) - Return 0 - End Function - - Private Function Lua_ComReadShortVar(ByVal p As IntPtr) As Integer - Dim state = Lua.FromIntPtr(p) - Dim nVarAddr As Integer = 0 - Dim nMachine As Integer = 0 - LuaCheckParam(state, 1, nVarAddr) - LuaCheckParam(state, 2, nMachine) - LuaClearStack(state) - Dim Machine As NGP_COMM_DLL.NC.NC_generic - If nMachine = 1 Then - Machine = Map.refMainWindowVM.MachineManager.Machine1 - Else - Machine = Map.refMainWindowVM.MachineManager.Machine2 - End If - Dim nResult As Short = 0 - If Machine.ReadShortVar(nVarAddr, nResult) Then - state.PushNumber(nResult) - Return 1 - Else - Return 0 - End If - End Function - - Private Function Lua_ComReadBitVar(ByVal p As IntPtr) As Integer - Dim state = Lua.FromIntPtr(p) - Dim nVarAddr As Integer = 0 - Dim nBit As Integer = 0 - Dim nMachine As Integer = 0 - LuaCheckParam(state, 1, nVarAddr) - LuaCheckParam(state, 2, nBit) - LuaCheckParam(state, 3, nMachine) - LuaClearStack(state) - Dim Machine As NGP_COMM_DLL.NC.NC_generic - If nMachine = 1 Then - Machine = Map.refMainWindowVM.MachineManager.Machine1 - Else - Machine = Map.refMainWindowVM.MachineManager.Machine2 - End If - Dim bResult As Boolean = 0 - If Machine.ReadBitVar(nVarAddr, nBit, bResult) Then - state.PushBoolean(bResult) - Return 1 - Else - Return 0 - End If - End Function - - Private Function Lua_ComReadDoubleVar(ByVal p As IntPtr) As Integer - Dim state = Lua.FromIntPtr(p) - Dim nVarAddr As Integer = 0 - Dim nMachine As Integer = 0 - LuaCheckParam(state, 1, nVarAddr) - LuaCheckParam(state, 2, nMachine) - LuaClearStack(state) - Dim Machine As NGP_COMM_DLL.NC.NC_generic - If nMachine = 1 Then - Machine = Map.refMainWindowVM.MachineManager.Machine1 - Else - Machine = Map.refMainWindowVM.MachineManager.Machine2 - End If - Dim dResult As Double = 0 - If Machine.ReadDoubleVar(nVarAddr, dResult) Then - state.PushBoolean(dResult) - Return 1 - Else - Return 0 - End If - End Function - - Private Function Lua_ComWriteShortVar(ByVal p As IntPtr) As Integer - Dim state = Lua.FromIntPtr(p) - Dim nVarAddr As Integer = 0 - Dim nValue As Integer = 0 - Dim nMachine As Integer = 0 - LuaCheckParam(state, 1, nVarAddr) - LuaCheckParam(state, 2, nValue) - LuaCheckParam(state, 3, nMachine) - LuaClearStack(state) - Dim Machine As NGP_COMM_DLL.NC.NC_generic - If nMachine = 1 Then - Machine = Map.refMainWindowVM.MachineManager.Machine1 - Else - Machine = Map.refMainWindowVM.MachineManager.Machine2 - End If - If Machine.WriteShortVar(nVarAddr, nValue) Then - state.PushBoolean(True) - Return 1 - Else - Return 0 - End If - End Function - - Private Function Lua_ComWriteBitVar(ByVal p As IntPtr) As Integer - Dim state = Lua.FromIntPtr(p) - Dim nVarAddr As Integer = 0 - Dim nBit As Integer = 0 - Dim bValue As Boolean = 0 - Dim nMachine As Integer = 0 - LuaCheckParam(state, 1, nVarAddr) - LuaCheckParam(state, 2, nBit) - LuaCheckParam(state, 3, bValue) - LuaCheckParam(state, 4, nMachine) - LuaClearStack(state) - Dim Machine As NGP_COMM_DLL.NC.NC_generic - If nMachine = 1 Then - Machine = Map.refMainWindowVM.MachineManager.Machine1 - Else - Machine = Map.refMainWindowVM.MachineManager.Machine2 - End If - If Machine.WriteBitVar(nVarAddr, nBit, bValue) Then - state.PushBoolean(True) - Return 1 - Else - Return 0 - End If - End Function - - Private Function Lua_ComWriteDoubleVar(ByVal p As IntPtr) As Integer - Dim state = Lua.FromIntPtr(p) - Dim nVarAddr As Integer = 0 - Dim dValue As Double = 0 - Dim nMachine As Integer = 0 - LuaCheckParam(state, 1, nVarAddr) - LuaCheckParam(state, 2, dValue) - LuaCheckParam(state, 3, nMachine) - LuaClearStack(state) - Dim Machine As NGP_COMM_DLL.NC.NC_generic - If nMachine = 1 Then - Machine = Map.refMainWindowVM.MachineManager.Machine1 - Else - Machine = Map.refMainWindowVM.MachineManager.Machine2 - End If - If Machine.WriteDoubleVar(nVarAddr, dValue) Then - state.PushBoolean(True) - Return 1 - Else - Return 0 - End If - End Function - - Private Function Lua_ExecProcess(ByVal p As IntPtr) As Integer - Dim state = Lua.FromIntPtr(p) - Dim sFileName As String = "" - Dim sMainLuaPath As String = "" - Dim sArguments As String = "" - LuaCheckParam(state, 1, sFileName) - LuaCheckParam(state, 2, sMainLuaPath) - LuaCheckParam(state, 3, sArguments) - LuaClearStack(state) - If ExecProcessManager.ExecProcess(sFileName, sMainLuaPath, sArguments) Then - state.PushBoolean(True) - Return 1 - Else - Return 0 - End If - End Function - - Friend Function LuaInstallGeneral(state As Lua) As Boolean - If IsNothing(state) Then Return False - state.Register("EntIs64bit", func_EntIs64bit) - state.Register("EntOutLog", func_EntOutLog) - state.Register("EntExistsDirectory", func_EntExistsDirectory) - state.Register("EntCopyFile", func_EntCopyFile) - state.Register("EntGetIniFile", func_EntGetIniFile) - state.Register("EntGetDataDir", func_EntGetDataDir) - state.Register("EntGetNumberFromIni", func_EntGetNumberFromIni) - state.Register("EntGetStringFromIni", func_EntGetStringFromIni) - state.Register("EntWriteStringToIni", func_EntWriteStringToIni) - state.Register("RdsStringGet", func_RdsStringGet) - state.Register("RdsStringSetAsync", func_RdsStringSetAsync) - state.Register("RdsPublishAsync", func_RdsPublishAsync) + Private Function Lua_EntOutLog(ByVal p As IntPtr) As Integer + Dim state = Lua.FromIntPtr(p) + ' 1 o 2 parametri : stringa da emettere [, DebugLevel = 0] + Dim sLogMsg As String = "" + Dim nDebugLevel As Integer = 0 + LuaCheckParam(state, 1, sLogMsg) + LuaGetParam(state, 2, nDebugLevel) + LuaClearStack(state) + ' accodo il messaggio nel file di log + EgtOutLog(sLogMsg) + ' non c'è risultato + Return 0 + End Function + + Private Function Lua_EntExistsDirectory(ByVal p As IntPtr) As Integer + Dim state = Lua.FromIntPtr(p) + ' 1 parametro : sDir + Dim sDirectory As String = "" + LuaCheckParam(state, 1, sDirectory) + LuaClearStack(state) + Dim bResult As Boolean + Try + ' verifico esistenza direttorio + bResult = Directory.Exists(sDirectory) + Catch ex As Exception + bResult = False + EgtOutLog("Lua_EntExistsDirectory on " & sDirectory & " failed! " & ex.Message) + End Try + ' restituisco il risultato + LuaSetParam(state, bResult) + Return 1 + End Function + + Private Function Lua_EntCopyFile(ByVal p As IntPtr) As Integer + Dim state = Lua.FromIntPtr(p) + ' 2 parametri : sFile, sNewFile + Dim sSourcePath As String = "" + Dim sDestinationPath As String = "" + LuaCheckParam(state, 1, sSourcePath) + LuaCheckParam(state, 2, sDestinationPath) + LuaClearStack(state) + Dim bResult As Boolean + Try + ' copio il file + File.Copy(sSourcePath, sDestinationPath, True) + bResult = True + Catch ex As Exception + bResult = False + EgtOutLog("Lua_EntCopyFile from " & sSourcePath & " to " & sDestinationPath & " failed! " & ex.Message) + End Try + ' restituisco il risultato + LuaSetParam(state, bResult) + Return 1 + End Function + + Private Function Lua_EntGetIniFile(ByVal p As IntPtr) As Integer + Dim state = Lua.FromIntPtr(p) + ' restituisco il risultato + LuaSetParam(state, IniFile.sPath) + Return 1 + End Function + + Private Function Lua_EntGetDataDir(ByVal p As IntPtr) As Integer + Dim state = Lua.FromIntPtr(p) + ' restituisco il risultato + LuaSetParam(state, Map.refMainWindowVM.MainWindowM.sDataRoot) + Return 1 + End Function + + Private Function Lua_EntGetNumberFromIni(ByVal p As IntPtr) As Integer + Dim state = Lua.FromIntPtr(p) + ' 4 parametri: sSec, sKey, dDef, sIniFile + Dim sSec As String = "" + Dim sKey As String = "" + Dim dDef As Integer = 0 + Dim sIniFile As String = "" + LuaCheckParam(state, 1, sSec) + LuaCheckParam(state, 2, sKey) + LuaCheckParam(state, 3, dDef) + LuaCheckParam(state, 4, sIniFile) + LuaClearStack(state) + Dim nResult As Integer = GetPrivateProfileInt(sSec, sKey, dDef, sIniFile) + ' restituisco il risultato + LuaSetParam(state, nResult) + Return 1 + End Function + + Private Function Lua_EntGetStringFromIni(ByVal p As IntPtr) As Integer + Dim state = Lua.FromIntPtr(p) + ' 4 parametri: sSec, sKey, sDef, sIniFile + Dim sSec As String = "" + Dim sKey As String = "" + Dim sDef As String = 0 + Dim sIniFile As String = "" + LuaCheckParam(state, 1, sSec) + LuaCheckParam(state, 2, sKey) + LuaCheckParam(state, 3, sDef) + LuaCheckParam(state, 4, sIniFile) + LuaClearStack(state) + Dim sResult As String = "" + GetPrivateProfileString(sSec, sKey, sDef, sResult, sIniFile) + ' restituisco il risultato + LuaSetParam(state, sResult) + Return 1 + End Function + + Private Function Lua_EntWriteStringToIni(ByVal p As IntPtr) As Integer + Dim state = Lua.FromIntPtr(p) + ' 4 parametri: sSec, sKey, sVal, sIniFile + Dim sSec As String = "" + Dim sKey As String = "" + Dim sVal As Integer = 0 + Dim sIniFile As String = "" + LuaCheckParam(state, 1, sSec) + LuaCheckParam(state, 2, sKey) + LuaCheckParam(state, 3, sVal) + LuaCheckParam(state, 4, sIniFile) + LuaClearStack(state) + Dim bResult As Boolean = WritePrivateProfileString(sSec, sKey, sVal, sIniFile) + ' restituisco il risultato + LuaSetParam(state, bResult) + Return 1 + End Function + + Private Function Lua_RdsStringGet(ByVal p As IntPtr) As Integer + Dim state = Lua.FromIntPtr(p) + If IsNothing(Map.refMainWindowVM.RedisManager) OrElse IsNothing(Map.refMainWindowVM.RedisManager.Subscriber) Then + EgtOutLog("Error! Trying to get string from a non existent redis!") + LuaSetParam(state) + Return 1 + End If + ' 1 parametro: sKey + Dim sKey As String = "" + LuaCheckParam(state, 1, sKey) + LuaClearStack(state) + Dim Result As RedisValue + Result = Map.refMainWindowVM.RedisManager.RedisDb.StringGet(sKey) + ' restituisco il risultato + LuaSetParam(state, Result) + Return 1 + End Function + + Private Function Lua_RdsStringSetAsync(ByVal p As IntPtr) As Integer + If IsNothing(Map.refMainWindowVM.RedisManager) OrElse IsNothing(Map.refMainWindowVM.RedisManager.Subscriber) Then + EgtOutLog("Error! Trying to set string on a non existent redis!") + Return 0 + End If + Dim state = Lua.FromIntPtr(p) + ' 2 parametri: sKey, sVal + Dim sKey As String = "" + Dim sVal As String = 0 + LuaCheckParam(state, 1, sKey) + LuaCheckParam(state, 2, sVal) + LuaClearStack(state) + Map.refMainWindowVM.RedisManager.RedisDb.StringSetAsync(sKey, sVal) + Return 0 + End Function + + Private Function Lua_RdsPublishAsync(ByVal p As IntPtr) As Integer + If IsNothing(Map.refMainWindowVM.RedisManager) OrElse IsNothing(Map.refMainWindowVM.RedisManager.Subscriber) Then + EgtOutLog("Error! Trying to publish on a non existent redis!") + Return 0 + End If + Dim state = Lua.FromIntPtr(p) + ' 2 parametri: sKey, sVal + Dim sChannel As String = "" + Dim sMessage As String = 0 + LuaCheckParam(state, 1, sChannel) + LuaCheckParam(state, 2, sMessage) + LuaClearStack(state) + Map.refMainWindowVM.RedisManager.Subscriber.PublishAsync(sChannel, sMessage) + Return 0 + End Function + + Private Function Lua_ComReadShortVar(ByVal p As IntPtr) As Integer + Dim state = Lua.FromIntPtr(p) + Dim nVarAddr As Integer = 0 + Dim nMachine As Integer = 0 + LuaCheckParam(state, 1, nVarAddr) + LuaCheckParam(state, 2, nMachine) + LuaClearStack(state) + Dim Machine As NGP_COMM_DLL.NC.NC_generic + If nMachine = 1 Then + Machine = Map.refMainWindowVM.MachineManager.Machine1 + Else + Machine = Map.refMainWindowVM.MachineManager.Machine2 + End If + Dim nResult As Short = 0 + If Machine.ReadShortVar(nVarAddr, nResult) Then + state.PushNumber(nResult) + Return 1 + Else + Return 0 + End If + End Function + + Private Function Lua_ComReadBitVar(ByVal p As IntPtr) As Integer + Dim state = Lua.FromIntPtr(p) + Dim nVarAddr As Integer = 0 + Dim nBit As Integer = 0 + Dim nMachine As Integer = 0 + LuaCheckParam(state, 1, nVarAddr) + LuaCheckParam(state, 2, nBit) + LuaCheckParam(state, 3, nMachine) + LuaClearStack(state) + Dim Machine As NGP_COMM_DLL.NC.NC_generic + If nMachine = 1 Then + Machine = Map.refMainWindowVM.MachineManager.Machine1 + Else + Machine = Map.refMainWindowVM.MachineManager.Machine2 + End If + Dim bResult As Boolean = 0 + If Machine.ReadBitVar(nVarAddr, nBit, bResult) Then + state.PushBoolean(bResult) + Return 1 + Else + Return 0 + End If + End Function + + Private Function Lua_ComReadDoubleVar(ByVal p As IntPtr) As Integer + Dim state = Lua.FromIntPtr(p) + Dim nVarAddr As Integer = 0 + Dim nMachine As Integer = 0 + LuaCheckParam(state, 1, nVarAddr) + LuaCheckParam(state, 2, nMachine) + LuaClearStack(state) + Dim Machine As NGP_COMM_DLL.NC.NC_generic + If nMachine = 1 Then + Machine = Map.refMainWindowVM.MachineManager.Machine1 + Else + Machine = Map.refMainWindowVM.MachineManager.Machine2 + End If + Dim dResult As Double = 0 + If Machine.ReadDoubleVar(nVarAddr, dResult) Then + state.PushBoolean(dResult) + Return 1 + Else + Return 0 + End If + End Function + + Private Function Lua_ComWriteShortVar(ByVal p As IntPtr) As Integer + Dim state = Lua.FromIntPtr(p) + Dim nVarAddr As Integer = 0 + Dim nValue As Integer = 0 + Dim nMachine As Integer = 0 + LuaCheckParam(state, 1, nVarAddr) + LuaCheckParam(state, 2, nValue) + LuaCheckParam(state, 3, nMachine) + LuaClearStack(state) + Dim Machine As NGP_COMM_DLL.NC.NC_generic + If nMachine = 1 Then + Machine = Map.refMainWindowVM.MachineManager.Machine1 + Else + Machine = Map.refMainWindowVM.MachineManager.Machine2 + End If + If Machine.WriteShortVar(nVarAddr, nValue) Then + state.PushBoolean(True) + Return 1 + Else + Return 0 + End If + End Function + + Private Function Lua_ComWriteBitVar(ByVal p As IntPtr) As Integer + Dim state = Lua.FromIntPtr(p) + Dim nVarAddr As Integer = 0 + Dim nBit As Integer = 0 + Dim bValue As Boolean = 0 + Dim nMachine As Integer = 0 + LuaCheckParam(state, 1, nVarAddr) + LuaCheckParam(state, 2, nBit) + LuaCheckParam(state, 3, bValue) + LuaCheckParam(state, 4, nMachine) + LuaClearStack(state) + Dim Machine As NGP_COMM_DLL.NC.NC_generic + If nMachine = 1 Then + Machine = Map.refMainWindowVM.MachineManager.Machine1 + Else + Machine = Map.refMainWindowVM.MachineManager.Machine2 + End If + If Machine.WriteBitVar(nVarAddr, nBit, bValue) Then + state.PushBoolean(True) + Return 1 + Else + Return 0 + End If + End Function + + Private Function Lua_ComWriteDoubleVar(ByVal p As IntPtr) As Integer + Dim state = Lua.FromIntPtr(p) + Dim nVarAddr As Integer = 0 + Dim dValue As Double = 0 + Dim nMachine As Integer = 0 + LuaCheckParam(state, 1, nVarAddr) + LuaCheckParam(state, 2, dValue) + LuaCheckParam(state, 3, nMachine) + LuaClearStack(state) + Dim Machine As NGP_COMM_DLL.NC.NC_generic + If nMachine = 1 Then + Machine = Map.refMainWindowVM.MachineManager.Machine1 + Else + Machine = Map.refMainWindowVM.MachineManager.Machine2 + End If + If Machine.WriteDoubleVar(nVarAddr, dValue) Then + state.PushBoolean(True) + Return 1 + Else + Return 0 + End If + End Function + + Private Function Lua_ExecProcess(ByVal p As IntPtr) As Integer + Dim state = Lua.FromIntPtr(p) + Dim sFileName As String = "" + Dim sMainLuaPath As String = "" + Dim sArguments As String = "" + LuaCheckParam(state, 1, sFileName) + LuaCheckParam(state, 2, sMainLuaPath) + LuaCheckParam(state, 3, sArguments) + LuaClearStack(state) + If ExecProcessManager.ExecProcess(sFileName, sMainLuaPath, sArguments) Then + state.PushBoolean(True) + Return 1 + Else + Return 0 + End If + End Function + + Friend Function LuaInstallGeneral(state As Lua) As Boolean + If IsNothing(state) Then Return False + state.Register("EntIs64bit", func_EntIs64bit) + state.Register("EntOutLog", func_EntOutLog) + state.Register("EntExistsDirectory", func_EntExistsDirectory) + state.Register("EntCopyFile", func_EntCopyFile) + state.Register("EntGetIniFile", func_EntGetIniFile) + state.Register("EntGetDataDir", func_EntGetDataDir) + state.Register("EntGetNumberFromIni", func_EntGetNumberFromIni) + state.Register("EntGetStringFromIni", func_EntGetStringFromIni) + state.Register("EntWriteStringToIni", func_EntWriteStringToIni) + state.Register("EntExecProcess", func_EntExecProcess) + state.Register("RdsStringGet", func_RdsStringGet) + state.Register("RdsStringSetAsync", func_RdsStringSetAsync) + state.Register("RdsPublishAsync", func_RdsPublishAsync) state.Register("ComReadShortVar", func_ComReadShortVar) state.Register("ComWriteShortVar", func_ComWriteShortVar) state.Register("ComReadDoubleVar", func_ComReadDoubleVar) @@ -398,6 +400,6 @@ Public Module Lua_General state.Register("ComReadBitVar", func_ComReadBitVar) state.Register("ComWriteBitVar", func_ComWriteBitVar) Return True - End Function - -End Module + End Function + +End Module