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

Gammon Forum

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

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Scripting Languages, Pros and Cons
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Scripting Languages, Pros and Cons

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


Pages: 1 2  

Posted by Gore   (207 posts)  [Biography] bio
Date Fri 16 Feb 2007 05:17 PM (UTC)
Message
Could anyone illustrate the pro's and con's of each scripting language that mushclient provides support for? Why should I use Lua over Python, and vice versa? Any other languages worth noting/using, and for what purpose?
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #1 on Fri 16 Feb 2007 06:15 PM (UTC)
Message
I would think that Python and Lua are the most reasonable choices if you were to pick solely on the merits of the language: features, cleanliness, etc.

But, Lua seems to get a lot more support around here. That alone is almost all I would need to pick Lua over everything else.

Oh, Lua also is quite portable, and will work for people using Wine and so forth.

Still, I think in the end of the day it depends on what you prefer. All the languages supported by MUSHclient are decent languages. If you're interested in programming after MUSHclient I'd look at Python and Lua, followed JScript, and VBscript and Perlscript last. (I've never seen people using Perlscript. VBscript is at least heavily used if you write little plug-in thingies for Microsoft Office products. JScript is used all over the web so it's important in that respect.)

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

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

Posted by Nick Gammon   Australia  (21,321 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Sat 17 Feb 2007 06:00 AM (UTC)
Message
The Lua scripting DLL is shipped with MUSHclient, so you can be sure that you (and anyone you give your scripts to), will have Lua.

Most Windows installations have VBscript and Jscript installed, so they can be used with a minimum of fuss.

The other languages have to be downloaded and installed, in some cases this can be a tedious process.

Lua is recommended these days, as a "common base" language, plus it is simple and easy to learn, yet very powerful when you get used to it.

- Nick Gammon

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

Posted by MattMc   USA  (54 posts)  [Biography] bio
Date Reply #3 on Mon 19 Feb 2007 12:28 AM (UTC)
Message
I think VBscript is the easiest for new coders.

Lua is the only language that supports grabbing the style of a line, so you'll need to know how to do that if you intend on being able to grab color codes from a line and duplicate it back easily (as far as I know).

The only plugin I've written in Perl was a socket to connect MUSHclient to a webserver for a bot. It works well, and I don't think any of the other languages would have been able to do that as easily.

Matt
[Go to top] top

Posted by Nick Gammon   Australia  (21,321 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Mon 19 Feb 2007 07:48 PM (UTC)
Message
Lua scripting also has various extra things which are not available to other script languages, namely everything on this page:

http://www.gammon.com.au/scripts/doc.php?general=lua

Message boxes, dialog boxes, input boxes, compression, hashing, regular expression processing (both native and PCRE, XML parsing, file picker dialog, progress-bar dialog, and a few other things like extra functionality (as mentioned by MattMc) for existing script functions.

Personally I don't think Lua is harder to learn than VBscript. For one thing, multiple lines in Lua are simply indicated by a line break, whereas with VBscript you have to use an underscore, eg.

Lua



ColourNote ("red", "blue",
            "Here is a long message .....")


VBscript



ColourNote "red", "blue", _
            "Here is a long message ....."


Note the underscore at the end of the first line, which can be fiddly to add/remove if you decide to wrap/unwrap lines.

- Nick Gammon

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

Posted by Shadowfyr   USA  (1,783 posts)  [Biography] bio
Date Reply #5 on Tue 20 Feb 2007 06:51 PM (UTC)
Message
Hmm. Yes, but its clearer and I can imagine that "some" situations may arise where using white space might confuse the parser. Though, if there are any statements that might create such a situation in Lua is far less certain. The reason you get by with it in Lua is that Lua requires () even in cases where VB doesn't. I.e., it clearly designates *start* and *stop* points for things like function parameters, while VB is sloppier about that.
[Go to top] top

Posted by Nick Gammon   Australia  (21,321 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Tue 20 Feb 2007 07:17 PM (UTC)

Amended on Tue 20 Feb 2007 07:18 PM (UTC) by Nick Gammon

Message
Exactly. And the reason you need to do that is because functions are "first class values" in Lua. What that means is they can be assigned, just like other variables, which you can't do in VBscript. Here is an example:


function f (a)
  return a * 2
end -- function f

b = f (10)   --> call function f

print (b)    --> 20

g = f        --> assign function f to variable g

b = g (20)   --> call function again

print (b)    --> 40


Note how in the above code, if you use f with the brackets, the function is called.

If you use f without the brackets, you are simply assigning the value of the function (that is, making a copy of the function reference).

You need the brackets when calling a function, even with no arguments, so Lua knows that you need to call it and not simply use the function reference itself.


- 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 #7 on Tue 20 Feb 2007 09:45 PM (UTC)
Message
I don't think that the Lua parser can ever get confused by whitespace, since Lua is not a whitespace sensitive language. I think there is one exception, though, that I am not remembering at the moment.

And Lua does allow one situation where functions can be called without parentheses:

my_function "my_param"

It's a left-over from Lua's days as a configuration language. I don't remember if you're allowed to have any argument type but string, but that would be a very quick look-up in the Lua manual for anybody who's curious.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

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

Posted by Nick Gammon   Australia  (21,321 posts)  [Biography] bio   Forum Administrator
Date Reply #8 on Wed 21 Feb 2007 04:35 AM (UTC)

Amended on Wed 21 Feb 2007 04:37 AM (UTC) by Nick Gammon

Message
The exception is, that when calling a function, the opening parenthesis has to occur on the same line, as it is ambiguous whether you are assigning a function or calling it.

eg.


b = f
 (10)   --> error: ambiguous syntax (function call x new statement) near '('


This is because a function name may occur inside parenthese (I forget why), like this:


function f (a)
  print (a)
end -- function f

(f) (22)


Since a line can start with something inside brackets, it is ambiguous in this sort of case which one is intended, an assignment or a function call.


a = f
(g) (22)


You can disambiguate by using a semicolon, eg.


a = f;
(g) (22)


- 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 #9 on Wed 21 Feb 2007 05:02 AM (UTC)
Message
Oh, right, I knew it had something to do with functions, but had forgotten what it was. Good call.

Not sure why you'd want a function name to be within parentheses either. Since Lua does not allow assignments as expressions, it wouldn't be for that reason. Maybe it has to do with some kind of expression returning a function, but I'm not sure why you'd need parentheses in those cases.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

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

Posted by Shadowfyr   USA  (1,783 posts)  [Biography] bio
Date Reply #10 on Wed 21 Feb 2007 05:16 PM (UTC)

Amended on Wed 21 Feb 2007 05:17 PM (UTC) by Shadowfyr

Message
Quote:
a = f;
(g) (22)


Wait, what!?!

That is as confusing as hell even "with" the semicolon, at least to anyone that rationally assumes that () is *supposed* to designate parameters or some other distinct seperation of function. lol
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #11 on Wed 21 Feb 2007 06:07 PM (UTC)
Message
Parentheses can designate parameters to a function call but also expressions, and a function is an expression, so there's nothing terribly surprising about that syntax if you're familiar with other languages than e.g. VBScript. I'm not exactly sure why it's useful, but it's quite common to see a function call on the result of an expression.

e.g.
function g()
return function() return 5 end
end

print (g()()) -- 5

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

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

Posted by Nick Gammon   Australia  (21,321 posts)  [Biography] bio   Forum Administrator
Date Reply #12 on Wed 21 Feb 2007 07:04 PM (UTC)

Amended on Wed 21 Feb 2007 07:06 PM (UTC) by Nick Gammon

Message
Quote:

That is as confusing as hell even "with" the semicolon, at least to anyone that rationally assumes that () is *supposed* to designate parameters ...


There is an interesting discussion on this point, on this page:

http://www.wowace.com/wiki/Coding_Tips

One of the points made there, is that this can be a function call:


("foo bar"):sub(3, 5) == "o b"


This is because strings have an implied metatable (the string table), and thus that expression is really the same as:


string.sub("foo bar", 3, 5) == "o b"


The important point is, that using that construct, which the syntax of the language supports for a function call, means a function call can start with brackets.

Now whilst most people won't code like that, when language implementors sit down and write a language parser, they have to make it unambiguously support everything in the language specification, even if some things won't be written by humans.

Many languages have a "statement terminator" syntax, so that the parser can know when one statement ends, and another starts. For example:


  • C / C++ / PHP - statements are terminated by the ";" character

  • Cobol - statements are terminated at the end of the line, unless there is a "continuation character" in column 6 of the next punched card.

  • Visual Basic - statements are terminated at the end of the line, unless the line ends with the "_" character. Also, you can use ":" to separate multiple statements on one line.



Now Lua does not require a specific terminator character, however in occasional places it requires a semicolon to disambiguate.

I don't think I have ever found this to be a problem except when I occassionally put a function call on one line, and start its arguments on the next (usually because the line is very long). eg.


a = b + c + d + f
    (x, y, z)


This above code gives the error message. All you have to do is make sure the function name and its opening bracket are on the same line, either:


a = b + c + d + f (
    x, y, z)


or


a = b + c + d + 
    f (x, y, z)


or


a = b + c + d + f (x, y, z)


I think this one idiosyncracy is not too bad, as it lets you have multi-line statements, without either needing "_" at the end of each line (as in VB) or a semicolon at the end of every statement everywhere (as in C).

- Nick Gammon

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

Posted by Nick Gammon   Australia  (21,321 posts)  [Biography] bio   Forum Administrator
Date Reply #13 on Wed 21 Feb 2007 07:09 PM (UTC)

Amended on Wed 21 Feb 2007 07:10 PM (UTC) by Nick Gammon

Message
Quote:

... () is *supposed* to designate parameters ...


You can't really make that blanket statement anyway. Take for a simple example:


a = (3 + 4) * 5


In that case ( ... ) does not designate parameters.

- Nick Gammon

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

Posted by Shadowfyr   USA  (1,783 posts)  [Biography] bio
Date Reply #14 on Thu 22 Feb 2007 07:43 PM (UTC)
Message
Well, I mean in context of placing it on the line alone really. Generally something like (g) would be an error, because it presumes something it being (returned) or some subdivision is happening, like in math, etc. Its just damned odd, and most compilers/interpretters would freak when running across it, because they assume you completely missed some part of the line, such as an assignment. In fact, I would be willing to bet that most would return some error like, "Error on line blah. Missing = in assignment." QBasic just says, "Error: Missing Statement". Which is basically the same thing as saying, "I expected something like 'a =' in front of that '(g)'.

Its just not standard in "any" language I ever hear of to allow it, since most of them assume that () without a function name in front of them is automatically the equivalent of placing '(4 + 4)' on a blank line by themselves. It can do the math, but has no idea what to "do" with it after, so simply doesn't allow it at all.
[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.


17,249 views.

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

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 FutureQuest]