Gammon Forum
Entire forum
MUSHclient
Lua
'io.popen' not implemented in MUSHclient
'io.popen' not implemented in MUSHclient
|
It is now over 60 days since the last post. This thread is closed.
  Refresh page
Posted by
| Andy.Liu
(22 posts) bio
|
Date
| Tue 07 Mar 2017 10:31 AM (UTC) |
Message
| It works on command line.
Thanks.
Code:
function callRemoteLua(keyword)
print(keyword)
local handler = io.popen("lua fengxianpoem.lua "..keyword)
local poem = handler:read("*all")
handler:close()
print("found answer:"..poem)
end
Run-time error
World: robotcat
Immediate execution
[string "Script file"]:920: 'io.popen' not implemented in MUSHclient
stack traceback:
[C]: in function 'popen'
[string "Script file"]:920: in function 'callRemoteLua'
[string "Script file"]:905: in function 'answerPoem4'
[string "触发器: "]:1: in main chunk
脚本错误处的上下文:
916 : end
917 :
918 : function callRemoteLua(keyword)
919 : print(keyword)
920*: local handler = io.popen("lua fengxianpoem.lua "..keyword)
921 : local poem = handler:read("*all")
922 : handler:close()
923 : print("found answer:"..poem)
924 : end | top |
|
Posted by
| Fiendish
USA (2,514 posts) bio
Global Moderator |
Date
| Reply #1 on Tue 07 Mar 2017 11:42 AM (UTC) Amended on Tue 07 Mar 2017 11:50 AM (UTC) by Fiendish
|
Message
| https://www.mushclient.com/scripts/doc.php?lua=io.popen says
Quote: io.popen is not supported under the version compiled into MUSHclient
Try this instead:
-- replacement for io.popen
-- or os.execute with output
function osexecute(cmd)
local n = GetInfo(66).."osexecute_temp_file.txt" -- temp file for catching output
cmd = cmd .. " > \""..n.."\""
local err = os.execute(cmd)
local messages = {}
for line in io.lines(n) do
table.insert(messages, line)
end
os.remove(n) -- remove temp file
return err, messages
end
But wait!
Are you calling another Lua from inside Lua? Why on earth would you do that?
Why not just import fengxianpoem.lua and call its functions? |
https://github.com/fiendish/aardwolfclientpackage | top |
|
Posted by
| Andy.Liu
(22 posts) bio
|
Date
| Reply #2 on Tue 07 Mar 2017 01:59 PM (UTC) |
Message
| Why I call another Lua script is because that I found that some dll only can be loaded in command line or console way.
So I can work around it by calling another Lua script which can call require("luaiconv") successfully.
I can get the output of another Lua which does many works for my logic and I just copy the result with simple function.
That's my purpose to call another Lua.
Thanks for your reply and I will try it later and back to you. | top |
|
Posted by
| Andy.Liu
(22 posts) bio
|
Date
| Reply #3 on Tue 07 Mar 2017 04:20 PM (UTC) |
Message
| I have tried but output nothing to the temp file.
Its size is zero.
But when I run the code in command line,it output correct result.
Maybe it is because of asynchronize http request.
I don't know the root cause. | top |
|
Posted by
| Nick Gammon
Australia (22,973 posts) bio
Forum Administrator |
Date
| Reply #4 on Tue 07 Mar 2017 08:40 PM (UTC) |
Message
| I've been trying to call luaiconv myself. Without success. Which characters sets are you translating from/to?
If you can require luaiconv from the command line you should be able to do it from your MUSHclient script. Maybe it isn't in your path or something like that. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|
Posted by
| Andy.Liu
(22 posts) bio
|
Date
| Reply #5 on Wed 08 Mar 2017 01:11 AM (UTC) |
Message
| I want to translate text between gbk and utf8 .
The text from mud is encoded in GBK but I handle It in lua in utf8
It works in Windows command line
I have installed lua5.1 by full package with an installer | top |
|
Posted by
| Andy.Liu
(22 posts) bio
|
Date
| Reply #6 on Wed 08 Mar 2017 01:15 AM (UTC) |
Message
| I have put dlls into the same directory which lua script file stayed.
they are all in mushclient/scripts | top |
|
Posted by
| Andy.Liu
(22 posts) bio
|
Date
| Reply #7 on Wed 08 Mar 2017 01:26 AM (UTC) |
Message
| I tried to load luaiconv with require "luaiconv" in mushclient lua script.
but it cannot find luaiconv. luaiconv placed in mushclient/scripts
and another copy in mushclient root directory also.
It doesn't work
so I want to call another lua which running in command line. | top |
|
Posted by
| Andy.Liu
(22 posts) bio
|
Date
| Reply #8 on Wed 08 Mar 2017 05:48 AM (UTC) |
Message
| I have worked around this issue.
There are 2 luas to complete the mission:
1.demo.lua
First,call fengxianpoem to fetech some html page and parse it by keyword. and write the result into a local text file.
Second,read the text file for result.
Full path of file or lua is required for mushclient,otherwise it failed.
function getScriptFilePath(fileName)
local mushSupport = true
if mushSupport then
return GetInfo(66).."scripts\\"..fileName
else
return fileName
end
end
function callRemoteFengxianLua(keyword)
keyword = string.gsub(keyword,"。","")
keyword = string.gsub(keyword,",",",")
print(keyword)
--Use fullpath
local script = getScriptFilePath("fengxianpoem.lua")
local resultPath = getScriptFilePath("fengxianpoemresult.txt")
local luacmd = "C:\\Program\ Files\\Lua\\5.1\\lua"
--lua shell command
local err = os.execute("\""..luacmd.."\" "..script.." "..keyword.." "..resultPath)
print("os.execute result:"..err)
--read result
local fileHandle = assert(io.open(resultPath,"r"),"failed to open file")
if fileHandle then
local dataUTF8 = fileHandle:read("*a");
print(dataUTF8)
end
fileHandle:close()
end
2.Fengxianpoem.lua
Fetech some data and parse it by keyword,save the result into a text file.
local keyword = "You failed when you get these words"
local filePath --full file path for writing result
if #arg>1 then
filePath = arg[2]
keyword = arg[1]
--print("keyword:"..keyword)
--print("filePath:"..filePath)
-- answerPoem5 fetech http page and parse it to result text,and write it to file.
----***luaiconv**** is called in this function.This is what I want.
---The lua script is running in command line so it works like that in command line.
local result = answerPoem5(keyword)
if not result then
result = ""
end
local fileHandle = assert(io.open(filePath,"w+"),"failed to open file")
--delay()
if fileHandle then
print("result:"..result)
fileHandle:write(result)
--delay()
fileHandle:close()
end
end
Thanks for your support.
I don't get require "luaiconv.dll" work yet.
And have no idea now. | 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.
21,584 views.
It is now over 60 days since the last post. This thread is closed.
  Refresh page
top
Quick links:
MUSHclient.
MUSHclient help.
Forum shortcuts.
Posting templates.
Lua modules.
Lua documentation.
Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.