Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Lua
➜ Convert VBScript to Lua
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Morat
(18 posts) Bio
|
| Date
| Mon 21 Dec 2009 09:48 PM (UTC) |
| Message
| Is it possible to write the following scripts in Lua or should I write plugins in VBScript instead?
I rather not use the function os.execute since the DOS pop-up is annoying.
Should I try using LuaCOM? (faq 27)
Accessing COM objects from Lua
http://mushclient.com/forum/?id=6022
This VBScript alias copies my log to the temp directory then opens it in an editor.
<aliases>
<alias
match="log"
enabled="y"
send_to="12"
sequence="100"
>
<send>Option Explicit
Sub Log
Dim objShell, objFile, strLOG, strTMP, strEditor
Set objShell = CreateObject("WScript.Shell")
Set objFile = CreateObject("Scripting.FileSystemObject")
strLOG = "C:\\Program Files\\MUSHclient\\logs\\DSL.LOG"
strTMP = objShell.ExpandEnvironmentStrings("%TMP%") & "\\DSL.LOG"
strEditor = "C:\\Program Files\\Vim\\vim72\\gvim.exe"
If objFile.FileExists(strLOG) Then
objFile.CopyFile strLOG, strTMP
End IF
objShell.Run Chr(34) & strEditor & Chr(34) & Chr(32) & Chr(34) & strTMP & Chr(34)
Set objFile = Nothing
Set objShell = Nothing
End Sub
Log</send>
</alias>
</aliases>
This VBScript alias searches an online equipment list. (i.e. submit form data, parse response, print)
<aliases>
<alias
match="search *"
enabled="y"
send_to="12"
sequence="100"
>
<send>Option Explicit
Dim strHTML
Sub GetEquipmentList
Dim objHTTP
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
objHTTP.Open "POST", "http://www.dsl-mud.org/algoron/equipment/keyword_items.asp"
objHTTP.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
objHTTP.Send "keyword=" & Replace("%1", " ", "+")
strHTML = objHTTP.ResponseText
End Sub
Sub FormatEquipmentList
Dim intX, intY, intZ, objRegExp
intX = instr(strHTML, "#EDBD70")
intY = instr(strHTML, vbCrLf & "</div>")
intZ = intY - intX
If intX = 0 Then
strHTML = "no equipment found"
Else
strHTML = mid(strHTML, intX, intZ)
Set objRegExp = New RegExp
objRegExp.Global = True
objRegExp.Pattern = "#EDBD70.."
strHTML = objRegExp.Replace(strHTML, "")
objRegExp.Pattern = ">\\s+<"
strHTML = objRegExp.Replace(strHTML, "><")
objRegExp.Pattern = "<tr>"
strHTML = objRegExp.Replace(strHTML, vbLf)
objRegExp.Pattern = "&nbsp;</td>"
strHTML = objRegExp.Replace(strHTML, " ")
objRegExp.Pattern = "<[^>]*>"
strHTML = objRegExp.Replace(strHTML, "")
End If
End Sub
GetEquipmentList
FormatEquipmentList
AnsiNote vbLf & ANSI(32) & strHTML</send>
</alias>
</aliases>
| | Top |
|
| Posted by
| Nick Gammon
Australia (23,165 posts) Bio
Forum Administrator |
| Date
| Reply #1 on Tue 22 Dec 2009 01:55 AM (UTC) |
| Message
| To load an editor, see:
Something like this should work:
assert (package.loadlib ("windows_utils.dll", "luaopen_windows_utils")) ()
assert (windows_utils.shell_execute (
strEditor, -- program
'"' .. strLOG .. '"' -- argument
))
As for querying a web page, try:
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Morat
(18 posts) Bio
|
| Date
| Reply #2 on Wed 23 Dec 2009 02:44 AM (UTC) Amended on Sat 23 Jan 2010 02:27 PM (UTC) by Morat
|
| Message
| Thanks for reply. I got it all working.
Here is how to submit a web form with LuaSocket if someone else needs it.
local http = require "socket.http"
local requestbody = "keyword=" .. string.gsub("leather bracer", " ", "+")
local responsebody = {}
http.request {
url = "http://www.dsl-mud.org/algoron/equipment/keyword_items.asp",
method = "POST",
headers = {
["content-type"] = "application/x-www-form-urlencoded",
["content-length"] = string.len(requestbody)
},
source = ltn12.source.string(requestbody),
sink = ltn12.sink.table(responsebody)
}
local html = table.concat(responsebody)
print(html)
I got LuaCOM working to copy my log to the temp directory then open it in an editor.
assert(package.loadlib("luacom.dll", "luacom_open"))()
local sh = luacom.CreateObject("WScript.Shell")
sh:Run('cmd.exe /C copy /Y logs\\\\DSL.LOG %TEMP%\\\\DSL.LOG', 0, true)
sh:Run('"%ProgramFiles%\\\\Vim\\\\vim72\\\\gvim.exe" %TEMP%\\\\DSL.LOG', 1)
0 - Hides the window and activates another window.
1 - Activates and displays a window.
true - Wait for command to finish executing before continuing. | | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
19,634 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top