How does one return a value from internal Lua scripts back to TCC?
I am trying to use Lua scripts for TCC tab completion purposes, but the script invocation seems to return 0 always.
Here is example script:
-- Mercurial (hg) tab completion for Take Command
--
-- Install the script with command:
-- tabcomplete /l C:\..location..\hgcomplete.lua
require "winapi" -- from stevedonovan/winapi
require "os"
command = arg[1]
if command ~= "hg" then
print("NOT hg COMMAND")
return 1
end
print("HG command detected: " .. command)
possible_params = {
"add",
"branch",
"clone",
"commit",
"export",
"fold",
"heads",
"merge",
"status",
"push",
"pull",
"revert",
"rm",
"init" }
winapi.setenv("TABCOMPLETIONRESULT", table.concat(possible_params, " "))
return 0
Running "tabcomplete /l C:\..location..\hgcomplete.lua" and trying to complete "hg" command works, but the script breaks completion for all other commands (since "return 1" seems to be treated as "return 0" by TCC).
I can work-around this by creating a small .btm script and replacing all return statements with os.exit(X) in lua code:
@ECHO OFF
@REM hgcomplete.btm - tabcomplete /l c:\..location..\hgcomplete.btm
@D:\code\3rdparty\lua\lua-5.3.5\src\lua.exe c:\work\lua\tabcomplete_hg\hgcomplete_btm.lua %*
@exit /b %?
But in this case, I am calling external Lua and internal Lua is ignored.
Here is the os.exit() variant of hgcomplete.lua:
require "winapi" -- from stevedonovan/winapi
require "os"
command = arg[1]
if command ~= "hg" then
print("NOT hg COMMAND")
os.exit(1)
end
print("HG command detected: " .. command)
possible_params = {
"add",
"branch",
"clone",
"commit",
"export",
"fold",
"heads",
"merge",
"status",
"push",
"pull",
"revert",
"rm",
"init" }
winapi.setenv("TABCOMPLETIONRESULT", table.concat(possible_params, " "))
os.exit(0)
Also note that os.exit() cannot be called from internal Lua scripts since it will end the complete TCC process!
I am trying to use Lua scripts for TCC tab completion purposes, but the script invocation seems to return 0 always.
Here is example script:
-- Mercurial (hg) tab completion for Take Command
--
-- Install the script with command:
-- tabcomplete /l C:\..location..\hgcomplete.lua
require "winapi" -- from stevedonovan/winapi
require "os"
command = arg[1]
if command ~= "hg" then
print("NOT hg COMMAND")
return 1
end
print("HG command detected: " .. command)
possible_params = {
"add",
"branch",
"clone",
"commit",
"export",
"fold",
"heads",
"merge",
"status",
"push",
"pull",
"revert",
"rm",
"init" }
winapi.setenv("TABCOMPLETIONRESULT", table.concat(possible_params, " "))
return 0
Running "tabcomplete /l C:\..location..\hgcomplete.lua" and trying to complete "hg" command works, but the script breaks completion for all other commands (since "return 1" seems to be treated as "return 0" by TCC).
I can work-around this by creating a small .btm script and replacing all return statements with os.exit(X) in lua code:
@ECHO OFF
@REM hgcomplete.btm - tabcomplete /l c:\..location..\hgcomplete.btm
@D:\code\3rdparty\lua\lua-5.3.5\src\lua.exe c:\work\lua\tabcomplete_hg\hgcomplete_btm.lua %*
@exit /b %?
But in this case, I am calling external Lua and internal Lua is ignored.
Here is the os.exit() variant of hgcomplete.lua:
require "winapi" -- from stevedonovan/winapi
require "os"
command = arg[1]
if command ~= "hg" then
print("NOT hg COMMAND")
os.exit(1)
end
print("HG command detected: " .. command)
possible_params = {
"add",
"branch",
"clone",
"commit",
"export",
"fold",
"heads",
"merge",
"status",
"push",
"pull",
"revert",
"rm",
"init" }
winapi.setenv("TABCOMPLETIONRESULT", table.concat(possible_params, " "))
os.exit(0)
Also note that os.exit() cannot be called from internal Lua scripts since it will end the complete TCC process!