5005fd3e73
- aggiornate versioni
559 lines
21 KiB
VB.net
559 lines
21 KiB
VB.net
Imports System.IO
|
|
Imports KeraLua
|
|
Imports StackExchange.Redis
|
|
Imports Effector.Plugin.Lib
|
|
|
|
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_EntFileExists As LuaFunction = AddressOf Lua_EntFileExists
|
|
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_EntGetMainNumberFromIni As LuaFunction = AddressOf Lua_EntGetMainNumberFromIni
|
|
Friend func_EntGetMainStringFromIni As LuaFunction = AddressOf Lua_EntGetMainStringFromIni
|
|
Friend func_EntWriteMainStringToIni As LuaFunction = AddressOf Lua_EntWriteMainStringToIni
|
|
Friend func_EntSplitString As LuaFunction = AddressOf Lua_EntSplitString
|
|
Friend func_EntSleep As LuaFunction = AddressOf Lua_EntSleep
|
|
Friend func_EntDeleteFile As LuaFunction = AddressOf Lua_EntDeleteFile
|
|
Friend func_EntFileLength As LuaFunction = AddressOf Lua_EntFileLength
|
|
Friend func_EntExecProcess As LuaFunction = AddressOf Lua_EntExecProcess
|
|
Friend func_EntStateMachineOutText As LuaFunction = AddressOf Lua_EntStateMachineOutText
|
|
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
|
|
Friend func_ComWriteDoubleVar As LuaFunction = AddressOf Lua_ComWriteDoubleVar
|
|
Friend func_ComReadBitVar As LuaFunction = AddressOf Lua_ComReadBitVar
|
|
Friend func_ComWriteBitVar As LuaFunction = AddressOf Lua_ComWriteBitVar
|
|
Friend func_ComCopyFileToNc As LuaFunction = AddressOf Lua_ComCopyFileToNc
|
|
|
|
Private Function Lua_EntIs64bit(ByVal p As IntPtr) As Integer
|
|
Dim state = Lua.FromIntPtr(p)
|
|
state.PushBoolean(Not IntPtr.Size = 4)
|
|
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_EntFileExists(ByVal p As IntPtr) As Integer
|
|
Dim state = Lua.FromIntPtr(p)
|
|
' 1 parametro : sDir
|
|
Dim sFilePath As String = ""
|
|
LuaCheckParam(state, 1, sFilePath)
|
|
LuaClearStack(state)
|
|
Dim bResult As Boolean
|
|
Try
|
|
' verifico esistenza direttorio
|
|
bResult = File.Exists(sFilePath)
|
|
Catch ex As Exception
|
|
bResult = False
|
|
EgtOutLog("Lua_EntExistsDirectory on " & sFilePath & " 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 = False
|
|
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_EntDeleteFile(ByVal p As IntPtr) As Integer
|
|
Dim state = Lua.FromIntPtr(p)
|
|
' 2 parametri : sFile, sNewFile
|
|
Dim sSourcePath As String = ""
|
|
LuaCheckParam(state, 1, sSourcePath)
|
|
LuaClearStack(state)
|
|
Dim bResult As Boolean
|
|
Try
|
|
' copio il file
|
|
File.Delete(sSourcePath)
|
|
bResult = True
|
|
Catch ex As Exception
|
|
bResult = False
|
|
EgtOutLog("Lua_EntDeleteFile" & sSourcePath & " 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 dResult As Double = GetPrivateProfileDouble(sSec, sKey, dDef, sIniFile)
|
|
' restituisco il risultato
|
|
LuaSetParam(state, dResult)
|
|
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_EntGetMainNumberFromIni(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
|
|
LuaCheckParam(state, 1, sSec)
|
|
LuaCheckParam(state, 2, sKey)
|
|
LuaCheckParam(state, 3, dDef)
|
|
LuaClearStack(state)
|
|
Dim dResult As Double = GetMainPrivateProfileDouble(sSec, sKey, dDef)
|
|
' restituisco il risultato
|
|
LuaSetParam(state, dResult)
|
|
Return 1
|
|
End Function
|
|
|
|
Private Function Lua_EntGetMainStringFromIni(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
|
|
LuaCheckParam(state, 1, sSec)
|
|
LuaCheckParam(state, 2, sKey)
|
|
LuaCheckParam(state, 3, sDef)
|
|
LuaClearStack(state)
|
|
Dim sResult As String = ""
|
|
GetMainPrivateProfileString(sSec, sKey, sDef, sResult)
|
|
' restituisco il risultato
|
|
LuaSetParam(state, sResult)
|
|
Return 1
|
|
End Function
|
|
|
|
Private Function Lua_EntWriteMainStringToIni(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
|
|
LuaCheckParam(state, 1, sSec)
|
|
LuaCheckParam(state, 2, sKey)
|
|
LuaCheckParam(state, 3, sVal)
|
|
LuaClearStack(state)
|
|
Dim bResult As Boolean = WriteMainPrivateProfileString(sSec, sKey, sVal)
|
|
' restituisco il risultato
|
|
LuaSetParam(state, bResult)
|
|
Return 1
|
|
End Function
|
|
|
|
Private Function Lua_EntSplitString(ByVal p As IntPtr) As Integer
|
|
Dim state = Lua.FromIntPtr(p)
|
|
' 4 parametri: sSec, sKey, sVal, sIniFile
|
|
Dim sVal As String = ""
|
|
Dim sSeparator As Char = ","c
|
|
LuaCheckParam(state, 1, sVal)
|
|
LuaGetParam(state, 2, sSeparator)
|
|
LuaClearStack(state)
|
|
Dim sSplitString() As String = sVal.Split(sSeparator)
|
|
' restituisco il risultato
|
|
LuaSetParam(state, sSplitString)
|
|
Return 1
|
|
End Function
|
|
|
|
Private Function Lua_EntSleep(ByVal p As IntPtr) As Integer
|
|
Dim state = Lua.FromIntPtr(p)
|
|
' 4 parametri: sSec, sKey, sVal, sIniFile
|
|
Dim nSleepTime As Integer = 0
|
|
LuaCheckParam(state, 1, nSleepTime)
|
|
LuaClearStack(state)
|
|
Threading.Thread.Sleep(nSleepTime)
|
|
Return 0
|
|
End Function
|
|
|
|
Private Function Lua_EntFileLength(ByVal p As IntPtr) As Integer
|
|
Dim state = Lua.FromIntPtr(p)
|
|
' 4 parametri: sSec, sKey, sVal, sIniFile
|
|
Dim sFilePath As String = 0
|
|
LuaCheckParam(state, 1, sFilePath)
|
|
LuaClearStack(state)
|
|
If String.IsNullOrWhiteSpace(sFilePath) Then Return 0
|
|
Dim FileInfo As New FileInfo(sFilePath)
|
|
If IsNothing(FileInfo) Then Return 0
|
|
LuaSetParam(state, FileInfo.Length)
|
|
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 = Map.refMainWindowVM.MachineManager.MachineList(nMachine - 1)
|
|
Dim nResult As Short = 0
|
|
If Machine.ReadShortVar(nVarAddr, nResult) Then
|
|
state.PushInteger(nResult)
|
|
Return 1
|
|
Else
|
|
EgtOutLog("Error reading variable " & nVarAddr & " on machine " & nMachine & ": " & Machine.ErrMsg)
|
|
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 = Map.refMainWindowVM.MachineManager.MachineList(nMachine - 1)
|
|
Dim bResult As Boolean = 0
|
|
If Machine.ReadBitVar(nVarAddr, nBit, bResult) Then
|
|
state.PushBoolean(bResult)
|
|
Return 1
|
|
Else
|
|
EgtOutLog("Error reading variable " & nVarAddr & " on machine " & nMachine & ": " & Machine.ErrMsg)
|
|
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 = Map.refMainWindowVM.MachineManager.MachineList(nMachine - 1)
|
|
Dim dResult As Double = 0
|
|
If Machine.ReadDoubleVar(nVarAddr, dResult) Then
|
|
state.PushNumber(dResult)
|
|
Return 1
|
|
Else
|
|
EgtOutLog("Error reading variable " & nVarAddr & " on machine " & nMachine & ": " & Machine.ErrMsg)
|
|
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 = Map.refMainWindowVM.MachineManager.MachineList(nMachine - 1)
|
|
If Machine.WriteShortVar(nVarAddr, nValue) Then
|
|
state.PushBoolean(True)
|
|
Return 1
|
|
Else
|
|
EgtOutLog("Error writing " & nValue & " on variable " & nVarAddr & " on machine " & nMachine & ": " & Machine.ErrMsg)
|
|
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 = Map.refMainWindowVM.MachineManager.MachineList(nMachine - 1)
|
|
If Machine.WriteBitVar(nVarAddr, nBit, bValue) Then
|
|
state.PushBoolean(True)
|
|
Return 1
|
|
Else
|
|
EgtOutLog("Error writing " & bValue & " on variable " & nVarAddr & " on machine " & nMachine & ": " & Machine.ErrMsg)
|
|
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 = Map.refMainWindowVM.MachineManager.MachineList(nMachine - 1)
|
|
If Machine.WriteDoubleVar(nVarAddr, dValue) Then
|
|
state.PushBoolean(True)
|
|
Return 1
|
|
Else
|
|
EgtOutLog("Error writing " & dValue & " on variable " & nVarAddr & " on machine " & nMachine & ": " & Machine.ErrMsg)
|
|
Return 0
|
|
End If
|
|
End Function
|
|
|
|
Private Function Lua_ComCopyFileToNc(ByVal p As IntPtr) As Integer
|
|
Dim state = Lua.FromIntPtr(p)
|
|
Dim sSourcePath As String = ""
|
|
Dim sDestPath As String = ""
|
|
Dim nMachine As Integer = 0
|
|
LuaCheckParam(state, 1, sSourcePath)
|
|
LuaCheckParam(state, 2, sDestPath)
|
|
LuaCheckParam(state, 3, nMachine)
|
|
LuaClearStack(state)
|
|
Dim Machine As NGP_COMM_DLL.NC.NC_generic = Map.refMainWindowVM.MachineManager.MachineList(nMachine - 1)
|
|
If Machine.CopyFileToNc(sSourcePath, sDestPath) Then
|
|
state.PushBoolean(True)
|
|
Return 1
|
|
Else
|
|
EgtOutLog("Copy file " & sSourcePath & " to " & sDestPath & " failed! Error: " & Machine.ErrMsg)
|
|
Return 0
|
|
End If
|
|
End Function
|
|
|
|
Private Function Lua_EntExecProcess(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
|
|
|
|
Private Function Lua_EntStateMachineOutText(ByVal p As IntPtr) As Integer
|
|
Dim state = Lua.FromIntPtr(p)
|
|
Dim sMessage As String = ""
|
|
Dim nStateMachine As Integer = 0
|
|
LuaCheckParam(state, 1, sMessage)
|
|
LuaCheckParam(state, 2, nStateMachine)
|
|
LuaClearStack(state)
|
|
Dim StateMachine As FiniteStateMachine = Map.refMainWindowVM.FiniteStateMachineManager.FiniteStateMachineList(nStateMachine - 1)
|
|
StateMachine.SetMessageText(sMessage)
|
|
Return 0
|
|
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("EntFileExists", func_EntFileExists)
|
|
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("EntGetMainNumberFromIni", func_EntGetMainNumberFromIni)
|
|
state.Register("EntGetMainStringFromIni", func_EntGetMainStringFromIni)
|
|
state.Register("EntWriteMainStringToIni", func_EntWriteMainStringToIni)
|
|
state.Register("EntSplitString", func_EntSplitString)
|
|
state.Register("EntSleep", func_EntSleep)
|
|
state.Register("EntFileLength", func_EntFileLength)
|
|
state.Register("EntDeleteFile", func_EntDeleteFile)
|
|
state.Register("EntExecProcess", func_EntExecProcess)
|
|
state.Register("EntStateMachineOutText", func_EntStateMachineOutText)
|
|
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)
|
|
state.Register("ComWriteDoubleVar", func_ComWriteDoubleVar)
|
|
state.Register("ComReadBitVar", func_ComReadBitVar)
|
|
state.Register("ComWriteBitVar", func_ComWriteBitVar)
|
|
state.Register("ComCopyFileToNc", func_ComCopyFileToNc)
|
|
Return True
|
|
End Function
|
|
|
|
End Module
|