Run a Lua Script from LiveCode
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Run a Lua Script from LiveCode
Does anyone know how to run a Lua Script from LiveCode?
Re: Run a Lua Script from LiveCode
I'd imagine only by using a shell command. Is there a console application you would use to run a Lua script? (For example, with a vbscript you could open a command prompt and typeand have it execute in that context. (I know you could also leave out the "cscript.exe" and have it execute, but that would open in the wscript context which means you wouldn't be able to pick up results in the same manner, if that's important. Anyway the point is to try an get a way to work with Lua, so this is just an indication of how it might be possible to adapt it to get it to interact.)
Say I have an external file somewhere containing vbscript:
In Livecode I could
So the same technique should be able to be applied to trigger, and hopefully retrieve results
from a Lua script.
You may also find there is some mileage in a "start" command of the sort:depending on how you might call a Lua script from a command prompt. You might need to adjust the quoting, say wrapping the whole command and script paths in one set of quotes, for instance. Note that there is a "dummy" set of double quotes between the "start" and the (quoted) path - this is to act as an empty "placeholder" for a "title" of the console window (which you would have hidden anyway).
I hope this is at least helpful in some ways to give you a direction to go about adapting things to work with your Lua scripts.
Code: Select all
>cscript.exe "myVBScript.vbs"
Say I have an external file somewhere containing vbscript:
Code: Select all
result = InputBox("What is your favourite colour?")
WScript.echo result
Code: Select all
put "<the path to my vbscript file>" into tVBScriptFile
set the hideConsoleWindows to true
--the above line stops the black command prompt window from appearing on screen, however briefly
get shell("cscript.exe //nologo" && quote & tVBScriptFile & quote)
-- specifying cscript tells Windows to use the console interpreter for the vbscript execution,
-- rather than the Windows GUI interpreter
-- using the "nologo" switch means that the console result is not cluttered with the standard
-- Microsoft copyright text, which means it is easier to just pick up the returned value which is
-- placed in "it". (Note this is rather different from using a "do as VBScript" operation from
-- within Livecode directly, where a variable "result" in the VBS code is returned to Livecode
-- in "the result. But let's not muddy the waters with that now, the purpose here is to
-- see what can be adapted to get Lua scripts to work, which means a shell flavour is needed.)
put it into theReturnedValue
-- the Wscript.echo as the last line in the vbscript file sent that value to the console. Which
-- we retrieved with our "get" command, and can now use the value in "it"
answer "The VBScript routine told me that your favourite colour is" && theReturnedValue
-- so we got a value back from an external script.
from a Lua script.
You may also find there is some mileage in a "start" command of the sort:
Code: Select all
get shell ("start" && quote & quote && quote & thePathToTheLuaCommand & quote && quote & "thePathToTheLuaScript" & quote)
I hope this is at least helpful in some ways to give you a direction to go about adapting things to work with your Lua scripts.
Re: Run a Lua Script from LiveCode
Hi guys
I had a VBS file as I do as you said above ,It work well !
Do you know to how to put parameter from textbox of Livecode to InputBox of VBS?
Thanks you guys a lot
Quang
I had a VBS file as I do as you said above ,It work well !
Do you know to how to put parameter from textbox of Livecode to InputBox of VBS?
Thanks you guys a lot
Quang
Re: Run a Lua Script from LiveCode
You should be able to pass the parameters to the VBScript when you invoke it in the "get shell.." command from Livecode.
Within the VBScript file you can find the paramenters passed to it as arguments:(You may need to watch the number of quotes and spaces, and possibly even wrap the whole thing in an extra set of double quotes, which is what I had to do in some circumstances back on my Windows XP machine).
Within your VBScript you should be able to retrieve those results by:
Within the VBScript file you can find the paramenters passed to it as arguments:
Code: Select all
get shell("cscript.exe //nologo" && quote & tVBScriptFile & quote && quote & tParameter1 & quote && quote & tParameter2 & quote)
Within your VBScript you should be able to retrieve those results by:
Code: Select all
If WScript.Arguments.Count = 2 Then
'the first parameter from Livecode can be the InputBox title
tTitleFromLivecode = WScript.Arguments.Item(0)
'the second parameter from Livecode can be the InputBox
tDefaultContentFromLivecode = WScript.Arguments.Item(1)
Else
Wscript.Echo "Error: I was expecting two parameters to be passed from Livecode"
Wscript.Quit
'or whatever error handling
End If
tInputResult = InputBox("This input box should have a title of " & tTitleFromLivecode & _
" with a default content of " & tDefaultContentFromLivecode,tTitleFromLivecode,tDefaultContentFromLivecode)
Wscript.Echo tInputResult
Re: Run a Lua Script from LiveCode
Thanks SparkOut
No words to say Thank you a lot
Quang
No words to say Thank you a lot
Quang
Re: Run a Lua Script from LiveCode
Glad to help.
I also note that we are discussing VBScript here again, where the attempt was to find something that could be adapted to use a Lua script. Livecode can actually "do" a vbscript directly, without having to have an external file. The technique is subtly different in that the result is retrieved in a different way, and you can't (as far as I know) pass parameters to the script with this method. However, you can (as I believe you have already seen in discussion with Klaus on your other thread about AD) put a placeholder in the vbscript and replace the placeholder with contents of a variable before execution.
A little sampler stack shows this in action. Hopefully you can also use the above "shell" technique to get Lua scripts to run, and return a value somehow to Livecode.
I also note that we are discussing VBScript here again, where the attempt was to find something that could be adapted to use a Lua script. Livecode can actually "do" a vbscript directly, without having to have an external file. The technique is subtly different in that the result is retrieved in a different way, and you can't (as far as I know) pass parameters to the script with this method. However, you can (as I believe you have already seen in discussion with Klaus on your other thread about AD) put a placeholder in the vbscript and replace the placeholder with contents of a variable before execution.
A little sampler stack shows this in action. Hopefully you can also use the above "shell" technique to get Lua scripts to run, and return a value somehow to Livecode.
- Attachments
-
- VBScript tester.zip
- (1.81 KiB) Downloaded 298 times