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

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Using the socket library
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: Using the socket library
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please)
Maximum of 6000 characters. Text only please, no HTML.
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Pages: 1 2  3  4  

Posted by David Berthiaume   (202 posts)  [Biography] bio
Date Fri 10 Dec 2004 10:22 PM (UTC)  quote  ]
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

Posted by Nick Gammon   Australia  (19,509 posts)  [Biography] bio   Forum Administrator
Date Wed 08 Dec 2004 08:21 PM (UTC)  quote  ]
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 Shadowfyr   USA  (1,776 posts)  [Biography] bio
Date Wed 08 Dec 2004 04:09 PM (UTC)  quote  ]

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.

main {
__if (Schrodinger_Cat is Alive or version >= "XP"){
____if version = "Vista" then Performance /= Number_of_Cores;
____call Functional_Code();}
__else
____call Crash_Windows();}
[Go to top] top

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

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 Nick Gammon   Australia  (19,509 posts)  [Biography] bio   Forum Administrator
Date Tue 07 Dec 2004 09:16 PM (UTC)  quote  ]
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 Shadowfyr   USA  (1,776 posts)  [Biography] bio
Date Tue 07 Dec 2004 08:30 PM (UTC)  quote  ]

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.

main {
__if (Schrodinger_Cat is Alive or version >= "XP"){
____if version = "Vista" then Performance /= Number_of_Cores;
____call Functional_Code();}
__else
____call Crash_Windows();}
[Go to top] top

Posted by Nick Gammon   Australia  (19,509 posts)  [Biography] bio   Forum Administrator
Date Tue 07 Dec 2004 08:08 PM (UTC)  quote  ]
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 Nick Gammon   Australia  (19,509 posts)  [Biography] bio   Forum Administrator
Date Tue 07 Dec 2004 08:03 PM (UTC)  quote  ]

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 Shadowfyr   USA  (1,776 posts)  [Biography] bio
Date Tue 07 Dec 2004 07:34 PM (UTC)  quote  ]

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.

main {
__if (Schrodinger_Cat is Alive or version >= "XP"){
____if version = "Vista" then Performance /= Number_of_Cores;
____call Functional_Code();}
__else
____call Crash_Windows();}
[Go to top] top

Posted by Nick Gammon   Australia  (19,509 posts)  [Biography] bio   Forum Administrator
Date Tue 07 Dec 2004 07:01 PM (UTC)  quote  ]
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 Nick Gammon   Australia  (19,509 posts)  [Biography] bio   Forum Administrator
Date Tue 07 Dec 2004 06:58 PM (UTC)  quote  ]

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 Shadowfyr   USA  (1,776 posts)  [Biography] bio
Date Tue 07 Dec 2004 05:23 PM (UTC)  quote  ]
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. :(

main {
__if (Schrodinger_Cat is Alive or version >= "XP"){
____if version = "Vista" then Performance /= Number_of_Cores;
____call Functional_Code();}
__else
____call Crash_Windows();}
[Go to top] top

Posted by Shadowfyr   USA  (1,776 posts)  [Biography] bio
Date Tue 07 Dec 2004 04:57 PM (UTC)  quote  ]
Message
Well Nick. LuaCOM is a "COM" library for Lua. It is what allows you to use ActiveX at all. My Fireworks gadget, the mapper for a BattleTech based mud and virtually every other example of using an external application from insides a script all use ActiveX. If you do a google search on 'ActiveX Lua', the **only** pages that list are either the LuaCOM ones or adaptations of LuaCOM as plugins for other applications. Lua itself cannot do it natively, even though every other one, including I suspect PHP, all provide at least basic support for it. So yes, it does do more, since it is more or less 100% necessary to even connect to and control 90% of all the applications currently written for windows.

And Ksilyan.. Yes, Girder is designed to "control programs like WinAmp and Windows Media Player using infrared and wireless remote controls so you can sit back and enjoy your digital library from your couch." I am not sure what if anything the difference technically is between that and driving things from a text stream. This applications seems to have to respond to a wide number of different devices and while the scripts may define what to do about the signals recieved, the major portion of the application likely involved calling several different scripts/plugins, depending on 'which' remote or device signals it. Sounds a lot like triggers firing and calling scripts, but heh, what do I know. LuaCOM just happens to be one of the things installed to extend functionality. Apparently, it is used to drive a LCD Master component, which displays information about what one or more of the devices being controlled is doing.

In any case, I am not at all sure what the heck you seem to want Ksilyan. I don't know C++ well enough to even try writing an example and no examples I have given, including one that uses C++, is good enough for you. You can't seem to get past the potential delusion that Mushclient is so horribly different that it isn't even worth investigation by someone that actually can code something to test it. For now, Lua is useless to me, even for what I have already been using other languages to do.

main {
__if (Schrodinger_Cat is Alive or version >= "XP"){
____if version = "Vista" then Performance /= Number_of_Cores;
____call Functional_Code();}
__else
____call Crash_Windows();}
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio   Moderator
Date Tue 07 Dec 2004 09:07 AM (UTC)  quote  ]
Message
Like I said, Shadowfyr, I'll be convinced the day you come up with sample code in C++ that gets this to work and, as Nick said, does something other than sitting around waiting for iTunes. That is, a full-blown application (say, similar to MUSHclient), that oh-just-so-happens to have this little scripting component that can listen to external events.

Note that the sample script you gave works in an application caleld 'Girder', which claims to be a "Windows automation tool". Chances are, the whole point of the program is to sit around waiting for this kind of event - it is not at all like MUSHclient.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

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

Posted by Nick Gammon   Australia  (19,509 posts)  [Biography] bio   Forum Administrator
Date Tue 07 Dec 2004 03:37 AM (UTC)  quote  ]
Message
Well, I'm not sure what luacom offers, but does this application do anything else, except wait for tunes to change?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[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.


25,289 views.

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

[New subject]  Start a new subject   [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.

[Home]

Written by Nick Gammon - 5K

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

[Best viewed with any browser - 2K]    [Web site powered by FutureQuest.Net]