In fact, I am not using LuaMacros for Flight simulator so I have developed some special techniques for handling the passing parameters.
I am using lLuaMacros to trigger my python scripts, but parameters are required for my scripts.
Therefore, lmc_spawn cannot handle the requirement because only one parameter can be applied, which is occupied by the script name.
For instance, the following works.
lmc_spawn(python_path, program_path .. "ButtonEnd.py")
However,
lmc_spawn(python_path, program_path .. "ButtonEnd.py abc cde")
does not.
Therefore, I write a function something like this:
function run_execute(program, command, arg)
text = ""
full_command = "Start \"\" /B " .. program .. " \"".. command .. "\"" .. " " .. arg
print(full_command)
f = assert(io.popen(full_command, "r"))
for line in f:lines() do
text = text .. line .. " || " -- Cannot use "\n"
--print(line)
end -- for loop
f:close()
return text
end
Along with the undocumented function of "io.popen()", the command can be executed.
Also, the related implementation also enables the possibility of returning parameters.
For instance, you may write the python code to gain the value from "ClipBoard.py", etc. so as to return the value for your defined.
function getClipboard()
program = pythonw_path
command = program_path .. "GetClipboard.py"
text = ""
full_command = "Start /B " .. program .. " \"".. command .. "\""
--print(full_command)
f = assert(io.popen(full_command, "r"))
for line in f:lines() do
text = text .. line .. " \n " -- Cannot use "\n"
--print(line)
end -- for loop
f:close()
return text
end
Indeed, I have used the function to drive the Arduino board to send the IR command to my TV.
lmc_send_keys('^c')
res = getClipboard()
res = trim(res)
lmc_send_to_com('C3', res .. "\n")
================================================================
As my Windows and Office are Chinese versions, the title comparison provided by LuaMacros does not work on them.
Hence, I write the following code to deal with it.
function show_byte(tt)
text = ""
for i = 1,string.len(tt),1 do
text = text .. ", " .. string.byte(string.sub(tt,i,i))
end
print(string.sub(text,3)) -- cut the first two char "," " "
end
function chinese_compare(tt, carray)
if #carray == string.len(tt) then
print(string.len(tt))
print("Match in Size")
for i = 1,string.len(tt),1 do
if string.byte(string.sub(tt,i,i)) ~= carray then
return false
end
return true
end
else
return false
end
end
For each Chinese title, I use "show_byte(tt)" to obtain the byte values of them
tt = lmc_get_window_title()
print(tt)
show_byte(tt)
, while the following macro can be applied to do the comparison.
carray = {165, 92, 175, 224, 197, 220, 188, 198}
if (chinese_compare(tt, carray)) then
--Perform the task
end
I hope the sharing can help some of the users of LuaMacros.
Share of some tricks (Passing Parameter & Handle Titles with non-English Words)
-
- Posts: 14
- Joined: 06 Feb 2018, 05:23
Re: Share of some tricks (Passing Parameter & Handle Titles with non-English Words)
Adding support for more parameters to lmc_spawn is not difficult... if it helps.
Petr Medek
LUAmacros author
LUAmacros author
-
- Posts: 14
- Joined: 06 Feb 2018, 05:23
Re: Share of some tricks (Passing Parameter & Handle Titles with non-English Words)
May I know how can I do this?
Re: Share of some tricks (Passing Parameter & Handle Titles with non-English Words)
You can't, it has to be doe in luamacros code, then new release.
Wait a few days
Wait a few days
Petr Medek
LUAmacros author
LUAmacros author
-
- Posts: 14
- Joined: 06 Feb 2018, 05:23
Re: Share of some tricks (Passing Parameter & Handle Titles with non-English Words)
OK! wait for the new version!
-
- Posts: 14
- Joined: 06 Feb 2018, 05:23
Re: Share of some tricks (Passing Parameter & Handle Titles with non-English Words)
Finally, I find a solution to the support for multiple parameters.
c = program.." \""..arg1.."\" \""..arg2.."\" \""..arg3
lmc_spawn(c)
In fact, lmc_spawn adds an additional " after the .exe extension, so the additional " should before the first argument.
The following is my code for demonstration. As running python code requires the specification of python.exe so running the script needs for the passing of two parameters, namely, the script file and the option.
program_path = "C:\\Users\\WingKin\\Dropbox\\Small Tools\\"
python_path = "\"C:\\Program Files\\Python36\\python.exe\""
program = python_path
command = program_path .. "DownloadtoPath.py"
arg = "Collection_Run"
c = program.." \""..command.."\" \""..arg
lmc_spawn(c)
Hope the solution help before the new version!
c = program.." \""..arg1.."\" \""..arg2.."\" \""..arg3
lmc_spawn(c)
In fact, lmc_spawn adds an additional " after the .exe extension, so the additional " should before the first argument.
The following is my code for demonstration. As running python code requires the specification of python.exe so running the script needs for the passing of two parameters, namely, the script file and the option.
program_path = "C:\\Users\\WingKin\\Dropbox\\Small Tools\\"
python_path = "\"C:\\Program Files\\Python36\\python.exe\""
program = python_path
command = program_path .. "DownloadtoPath.py"
arg = "Collection_Run"
c = program.." \""..command.."\" \""..arg
lmc_spawn(c)
Hope the solution help before the new version!