[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Using the socket library

Using the socket library

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Pages: 1  2  3  4 

Posted by Shadowfyr   USA  (1,786 posts)  [Biography] bio
Date Reply #45 on Tue 07 Dec 2004 05:23 PM (UTC)
Message
Ok.. Help Nick.. I finally managed to download the LuaCOM and unzipped the needed files (key is don't use Getright, apparently the site doesn't like download managers):

luacom.lua
lua-4.0.dll
lua-5.0.dll
lualib-4.0.dll
lualib-5.0.dll
luacom-lua4-1.2.dll
luacom-lua5-1.2.dll

Into the Mushclient directory. However... When I try to use 'require ("luacom")', I get:

[string "program"]:1: could not load package `luacom' from path `?;?.lua'

When are the people that develop for Windows going to get that environment variables are DOS and you can't expect to have one set to the path you need? Sigh.. Any ideas what to do about this? Apparently using "C:\progra~1\mushclient\luacom.lua" eats the '\', while using '/' keeps them (love Linux to Windows ports...), but still gives the same error. Kind of hard to use external .lua files if it won't let you import them. :(
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #46 on Tue 07 Dec 2004 06:58 PM (UTC)

Amended on Tue 07 Dec 2004 07:00 PM (UTC) by Nick Gammon

Message
Hey, that was fun! First time I've got luacom working.

First, if anyone is looking for it, try here:


http://www.tecgraf.puc-rio.br/~rcerq/luacom/


Now comes the tricky bit <grin>.

In that archive you will find a heap of files, however you only need 2. In the bin subdirectory, copy these 2 files to your MUSHclient installation folder (ie. the one where mushclient.exe is) ...

luacom-lua5-1.2.dll
luacom.lua

Now, and this is the tricky bit, if you open a command window and type:

depends luacom-lua5-1.2.dll

... you will see that it is missing two DLLs:

LUA-5.0.DLL
LUALIB-5.0.DLL

Now that I did was to copy the existing lua.dll and lualib.dll which is supplied with MUSHclient to make a separate file with those names. That way I have the identical copy of Lua in luacom as in MUSHclient. However I note that they were also supplied with the luacom download so you could probably copy those too.

Now, typing:

require "luacom"

works. What this actually ends up doing is the equivalent of:

dofile "luacom.lua"

So, if the search path is confusing then you could do that instead. However it seems to work for me with the default search path of the current directory, provided that is where you put the files.


Quote:

When are the people that develop for Windows going to get that environment variables are DOS and you can't expect to have one set to the path you need?


The documentation for require states that it gets its path from the global variable LUA_PATH, as follows:

Quote:

To determine its path, require first checks the global variable LUA_PATH. If the value of LUA_PATH is a string, that string is the path. Otherwise, require checks the environment variable LUA_PATH. Finally, if both checks fail, require uses a fixed path (typically "?;?.lua", although it is easy to change that when you compile Lua).


Thus if you want to change the path you could have done this:


LUA_PATH = "blah/?;blah/?.lua"
require "foo"


What that does is substitute "foo" for the question mark, and then try to open:


blah/foo
blah/foo.lua





Having read the luacom manual (a bit) I have to say that it looks pretty cool. Using that, you can use COM objects from Lua, so (on Windows at least) you can go crazy and use COM *and* Lua as well.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #47 on Tue 07 Dec 2004 07:01 PM (UTC)
Message
Having re-read your post, it seems you had all the right files. Anyway, try the depends thing, to check the DLL has all its dependencies. I wasted quite a bit of time before with the loadlib function telling me a DLL wasn't there, when it was, when the problem really was that a required DLL (a DLL the DLL wanted) was not there.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Shadowfyr   USA  (1,786 posts)  [Biography] bio
Date Reply #48 on Tue 07 Dec 2004 07:34 PM (UTC)

Amended on Tue 07 Dec 2004 07:46 PM (UTC) by Shadowfyr

Message
Ack.. I am getting too:

luacom.lua:2: attempt to call global `loadlib' (a nil value)

Sigh.. Wonder what is wrong this time. I can't seem to win. lol

And 'depends.exe' appears to be something that is part of your Visual C++ tools or something, not (as usual) something from the OS itself. :( Also apparently doesn't come with any compiler, etc. that I have installed. Sigh... I am sure all the files are there though. This is annoying, but at least it was closer than yesterday.

Ah, found a site to get the utility:

http://www.dependencywalker.com/

--edit--
Well, this is quite annoying. All the right files are there according to the dependency checkers list, but it isn't bloody working... Still, at least I got a nice utility out of it.
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #49 on Tue 07 Dec 2004 08:03 PM (UTC)

Amended on Tue 07 Dec 2004 08:05 PM (UTC) by Nick Gammon

Message
Quote:

... 'depends.exe' appears to be something that is part of your Visual C++ tools or something, ...


Yes, I thought it might be. :)

Read this:


http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=4910


The default for MUSHclient is to sandbox Lua somewhat. Go to Global Preferences -> Lua. You should see something like this:



--[[

-- Lua initialization 

-- Default initialization supplied with version 3.52.

Use this to create a "sandbox" for safe execution of non-trusted scripts.

If you only run your own scripts or plugins then you may not need this.

The code in this area is executed after each Lua script space is created
but before any of your scripts are done. This can be used to initialise things
(eg. load DLLs, load files, set up variables) or to disable things as shown below.

By setting a function name to nil you effectively make it unavailable.

You can remove some functions from a library rather than all of them, eg.

  os.execute = nil  --> no operating system calls
  os.remove = nil   --> no deleting files
  os.rename = nil   --> no renaming files


This script will automatically be replaced if you completely delete it from
the Global Preferences, and restart MUSHclient. To avoid this, leave a comment
in (if you don't want any further action taken).

--]]

-- Example sandbox --

function MakeSandbox ()

  loadlib = nil   -- no loading DLLs
  io = nil        -- no disk IO
  os = nil        -- no operating system calls

-- These are probably OK, if the above are disallowed --

--  require = nil   -- no loading files
--  dofile = nil    -- no external scripts
--  loadfile = nil  -- ditto

end

-- default is to sandbox everything --

-- MakeSandbox ()  --> remove this line to remove protection

--[[

-- You can limit the behaviour to specific worlds, or specific plugins
-- by doing something like this:

if  GetWorldID () ~= "05becae638cf8ce8ee2baf08"  -- trusted world 1
and GetWorldID () ~= "76cbff65aecf520f42c0df35"  -- trusted world 2
then
  MakeSandbox ()
end

if GetPluginID () ~= "" then  -- don't trust plugins
  MakeSandbox ()
end

--]]



I got the same thing, I forgot to mention. I commented out the line in bold and it worked. Then reload the script file to re-instantiate the script engine.

Or, you could be more sophisticated and do what is suggested lower down, and only make the sandbox for certain worlds.

One of the sandboxed lines is:


loadlib = nil -- no loading DLLs


That will be your problem. :)

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #50 on Tue 07 Dec 2004 08:08 PM (UTC)
Message
Having done all that (copied the DLLs, fixed the sandbox) then this is a quick test:


dofile "luacom.lua"

excel = luacom.CreateObject("Excel.Application")
excel.Visible = true


That worked for me, Excel popped up.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Shadowfyr   USA  (1,786 posts)  [Biography] bio
Date Reply #51 on Tue 07 Dec 2004 08:30 PM (UTC)

Amended on Tue 07 Dec 2004 08:37 PM (UTC) by Shadowfyr

Message
Yep. That would tend to explain it. lol

Couldn't you, to be safer, set the sandbox function to load luacom, then nil the function? That way you still supply access to it, but disable the ability to load more. Though... Maybe not, the Luacom dlls may use loadlib themselves in some fashion for all I know, or the functions that access them. But might be worth a try.
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #52 on Tue 07 Dec 2004 09:16 PM (UTC)
Message
Yes, you could do this in the global Lua initialisation:


require "luacom"
MakeSandbox () 


That loads the loacom module and then disables the functions.

However it might be a bit of an illusory gain, as you can now use COM (eg. File Scripting Objects) to do quite a bit of harm.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #53 on Tue 07 Dec 2004 10:13 PM (UTC)

Amended on Tue 07 Dec 2004 10:16 PM (UTC) by David Haley

Message
Quote:
I am not sure what if anything the difference technically is between that and driving things from a text stream.
My point, Shadowfyr, is that as you state yourself you really have no idea what you're talking about - you don't know C++ and you've never written Windows applications with it. The main reason I keep asking you to show some C++ code is that I would like you to understand that it's not as easy as you seem to think it is. It's fine if you think it's possible. And if you want to show that it is, why don't you go make a program that does it? Continually insisting that things should be as you want them to be without giving any indication that it's possible in code is esentially hot air. If you don't know anything about it, by your own admission, then why are you trying to tell me that Girder and MUSHclient are the same kind of program? Your silly comparison of Girder's input receiving to MUSHclient's processing of text and triggers is just that, silly. :-)

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Shadowfyr   USA  (1,786 posts)  [Biography] bio
Date Reply #54 on Wed 08 Dec 2004 04:09 PM (UTC)

Amended on Wed 08 Dec 2004 04:11 PM (UTC) by Shadowfyr

Message
Sigh.. Ksilyan.. I have been programming for nearly 25 years or so. I don't happen to have coded in C++, only because I don't have a compiler, I hate the free ones that make what is already more complicated (coding without some auto-code generation for objects) even more complicated and I don't have the cash to buy one. It is irrelivant. Languages are languages, they may each have some quirks, but they all conform to programming logic, which I tend to be good enough at that I can think myself through most of an application before I ever write a single line of the code to make it work. C++ just makes you waste a lot of extra time just setting every bloody thing up to get to the point where you can do what you wanted in the first place. Can't imagine why I wouldn't want to spend a week to get to that point, just to prove mine.... I have tried to code in C++, I just got frustrated at how much extra junk you have to do to make anything work and the lack of any good tools to help design with GCC and other free versions.

But it is all irrelevant. The only *real* question is "What happens in an application where the script runs in the same thread as the application and you want to use Luacom?" And you are right, for all I know Girder runs Lua in a seperate thread, so it never has to actually suspend the script engine between uses. But trying to run more than one script at a time, each in its own thread, is probably going to get complicated. I can't imagine Girder's developer thinking that would be a briliant idea. But who knows, I may be completely wrong about just how big of a mess running dozens of scripts in dozens of seperate threads would really be... I would tend to suspects that most people would try to keep in simpler than that though and employ the same model Mushclient uses, "suspend scripts when not executing them".

But it is irrelevant what I do or don't know about how it works. Nick managed to figure out how to get Luacom to work, so now it is just a matter of testing it to see if event handling works as loaded through the script itself. If not, then it is back to the drawing board. It may end up turning out that the only way to do it would be to add a Win32 specific module to Mushclient, which could be gutted for other systems, that duplicated what Luacom does for events, but is usable in 'all' scripts, not just lua. Heck, we now have some place to get a 'good' source code example showing how to make it work, which is by itself more than I have managed to find in an entire year or searching through google. Lot of general examples, just nothing quite so specific to 'just' making a stand alone event manager, which you can use as a dll, until now.
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #55 on Wed 08 Dec 2004 08:21 PM (UTC)
Message
Quote:

Nick managed to figure out how to get Luacom to work ...


That's right. Looking on the bright side, even if we don't get the Winamp thing to work, our knowledge has increased in other directions. :)

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by David Berthiaume   (202 posts)  [Biography] bio
Date Reply #56 on Fri 10 Dec 2004 10:22 PM (UTC)
Message
You guys seem really amped up on this lua.

I've been scripting in VB since April 2001... And this Lua sounds pretty amazing, doing everything that I've wanted, pausing, frational second triggers and what not... Sounds like it's going to completely change the way scripting is done... I'm looking forward to it.
[Go to top] 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.


134,162 views.

This is page 4, subject is 4 pages long:  [Previous page]  1  2  3  4 

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] 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.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]