Your favourite language!

Posted by Nickpick on Mon 08 May 2006 09:29 AM — 20 posts, 85,910 views.

#0
So, which language do you use and why?

I've been using VBScript, but I'm seriously thinking of switching to Python, simply because VB syntax gets on my nerves.
USA #1
I use Lua because it's fast, powerful and very elegant as a language (both in practice and in principle). I also find it much easier to extend than most scripting languages. In general, I also like Lua because it has a much smaller footprint in disk and on memory than languages such as Python. And as a general nit-pick, I don't really like languages than use whitespace as a significant token (in Python, for instance, as a scoping indicator).
Australia Forum Administrator #2
Ah, Language Wars! This should be fun. :)


I too like Lua these days. It has a simple elegance, with a small formal definition, however can be extended pretty-much indefinitely by well-defined interfaces (that is, libraries).

Its string library has powerful functions, like its own regular expression parser, which my tests have shown is very fast.

You can handle runtime errors by wrapping any function into a "protected call" if you want.

Its table structure is very powerful at storing any sort of data keyed by any other sort of data. Tables can be nested.

Having said that, you can probably make a good case for any of the scripting languages, it is probably a case of "the right tool for the job".

Remember, Lua is freely available (no charge for it, no need to give an email address even). Unlike VBscript, it is cross-platform, and runs on any system that supports a C compiler, including Windows, Unix (Linux), and Macintosh.
#3
Well if we are on about languages my top favourite is C++, but since it's not a scripting language, there's little good it can do with MushClient.

About Python, Lua and Co., I'm just looking for something different than VBScript, which simply has an ugly syntax. I liked Python optically, but if you say that Lua is good, I might well try it too.
#4
By the way, any good and preferably free Lua editors you know? MUSHClient editor sure is nice, but sometimes you just want more colour.
USA #5
I recently switched to Lua myself. My old editor started crashing a lot (nothing to do with Lua) and in my search for a new one I found Crimson Editor, which has built in color syntax for lots of languages and it's well documented in the help on how to create your own syntax files for other languages or how modify current ones to meet your needs. I was really surprised that it came with a Lua syntax. It is free.
#6
Okey, one thing I need to admit already is that it is clearly faster than VBScript.
USA #7
I personnally use python for all my scripts, triggers, and such, as well as a few plugins. But for portability of plugins, a few that I have written use VBscript. I really like the way python's syntaxs are, especially the whitespace character as a scoping indicator,(because I dislike searching for or forgetting that one 'end' or brace). I use Cedit(Crimson Editor) and I love the ability it has to color file syntax, all .py,pyw, and once configured, .pys. Yeeep Monty Python is the language for me.
USA #8
I personally use SciTE from here:

http://scintilla.sourceforge.net/SciTEDownload.html

for editing. It supports every language imaginable and you can edit the definition files (with some limitations) to have it color Mushclient commands for the language(s) you use the same as its own. Frankly, the only thing that bugs me is that no "Extended commands" option exists with a unique color for commands that are not part of the language itself. Say, blue for the language commands and orange or something for Mushclient. To do that required recompiling the Scintilla lexer dll itself, last I checked.

However, so long as you don't mind that limitation, it will color the syntax of damn near everything I have ever heard of.
USA #9
Since we're talking about editors, I use vi (vim, actually) for most of my editing, even locally. It's one of the best editors, if not the best editor that I have used; once I got used to it of course. :-)
Australia Forum Administrator #10
Hmm, interesting. I had been using ScITE, however after trying Crimson Editor it also seems very nice.

Its home page:


http://www.crimsoneditor.com/


Quote:

Frankly, the only thing that bugs me is that no "Extended commands" option exists with a unique color for commands that are not part of the language itself.


I tried to add that to Crimson Editor with a good deal of success.

I edited the "key" file for Lua (in directory C:\Program Files\Crimson Editor\spec\lua.key) and added the following lines to the bottom. After reloading my script file all the MUSHclient script functions were coloured in orange.


[KEYWORDS3:GLOBAL]
#
# MUSHclient world library functions
#
Accelerator
AcceleratorList
Activate

... and so on ...

WorldPort
WriteLog

world



I entered the last one ("world") manually in case you did world.Note)

To generate the full list I did this in Lua:


for k, v in pairs (utils.functionlist ()) do
  print (v)
end


After that you can add the MUSHclient extra Lua libraries (like utils) by doing this:


for k in pairs (utils) do
  print ("utils", k)
end


(And then do the same thing for the "bit" library).


Of course, you could add the MUSHclient keywords to the key file for any language, not just Lua.
Amended on Wed 04 Jun 2008 09:17 PM by Nick Gammon
Australia Forum Administrator #11
There seemed to be a problem in Crimson Editor in detecting block comments, in that they were commented out in the lua.spc file. I suspect this is because the block comment delimiter was the same as the multi-line string delimiter. However this file contents *seemed* to work for me:


$CASESENSITIVE=YES
$DELIMITERS=(){}[]<>+-*/%="'~!@#&$^&|\?:;,.
$ESCAPECHAR=\
$QUOTATIONMARK1="
$QUOTATIONMARK2='
$LINECOMMENT=--
$SHADOWON=[[
$SHADOWOFF=]]
$BLOCKCOMMENTON=--[[
$BLOCKCOMMENTOFF=--]]
$PAIRS1=()
$PAIRS2=[]
$PAIRS3={}
$MULTILINESTRINGCONSTANT=YES



Strictly speaking, a multi-line comment is terminated by just "]]", not "--]]", however the Lua manual recommends using "--]]" because you can then simply include or exclude the entire multi-line block (assuming it is code) by simply adding an extra hyphen to the leading comment. Also, I think it looks more symmetrical.

To quote from their manual:




A common trick, when we want to comment out a piece of code, is to write the following:


    --[[
    print(10)         -- no action (comment)
    --]]


Now, if we add a single hyphen to the first line, the code is in again:


    ---[[
    print(10)         --> 10
    --]]


In the first example, the -- in the last line is still inside the block comment. In the second example, the sequence ---[[ does not start a block comment; so, the print is outside comments. In this case, the last line becomes an independent comment, as it starts with --.

[EDIT]

Added a new line, found on another forum:

$MULTILINESTRINGCONSTANT=YES

This lets it recognise multi-line string costants, like this:


print "hello, \
world"


Amended on Tue 16 May 2006 11:29 PM by Nick Gammon
Australia Forum Administrator #12
However, back to languages, one of the really nice things about Lua is its ability to treat functions as "first class values" (as the manual says). What this means is that functions can be:

  • assigned (eg. a = print)
  • passed as parameters to other functions
  • stored in tables
  • constructed on-the-fly (eg. a function defined as an argument to another function)
  • removed (eg. print = nil)
  • have their behaviour changed - for example redefining print to also log (by saving the previous value as a local variable and then assigning a new one to it)
  • have their environment changed - effectively this means that for a particular function call you can redefine its global address space, effectively "sandboxing" it
  • call in protected mode - thus catching any errors inside the function and reporting them, rather than having the script terminate


This leads to some nice elegant programming, for example the sort function can take as an argument a function that specifies the "less than" test, so you can have custom sort orders.
Amended on Mon 08 May 2006 10:00 PM by Nick Gammon
#13
Hmm.. Crimson does look nice.

On Lua tables: They really look like the arrays and I suppose they are arrays in a way. What I've been wondering about is whether it is possible to create 3D or 4D tables for Lua.
USA #14
Sure. You can create n-dimensional tables in Lua. Since tables can be nested, and arrays are a special case of tables, you can have tables of tables of tables of tables of tables of tables of ... tables of tables of ... integers. :-)

For example,
function Make2dMatrix(width)
  local result = {}
  for i = 1, width do
    result[i] = {}
  end
  return result
end

matrix = Make2dMatrix(3)
matrix[1][1] = 1
matrix[1][2] = 2
matrix[1][3] = 3
matrix[2][1] = 4
matrix[2][2] = 5
matrix[2][3] = 6
matrix[3][1] = 7
matrix[3][2] = 8
matrix[3][3] = 9

for row = 1, 3 do
  for col = 1, 3 do
    io.write(matrix[row][col], " ")
  end
  io.write("\n")
end


This generates a 3x3 matrix, fills it up with some values, and prints them all out. The output is:
$ lua tmp.lua 
1 2 3 
4 5 6 
7 8 9
Australia Forum Administrator #15
On the subject of editors, there was someone a while back that wanted an editor that would edit plugins but syntax colour the script part correctly (Shadowfyr maybe).

It seems Crimson Editor may do that, although I haven't actually tested it. In its syntax colouring configuration file you can specify "ranges" for colouring. An example is PHP files, where you syntax colour scripts between <?php ... ?> differently from the HTML code which is outside those delimiters.

Thus, it would seem quite possible to have it colour between <script> ... </script> differently to elsewhere, which should solve the problem.

You could also probably colour XML keywords (like "trigger", "alias" and so on), in the non-script part.
USA #16
Heh, don't pick on me Nick. ;) Seriously though, the discussion was with a number of us and about if Mushclient might at some point support something like Scintilla in its own editor. This was based on the fact that some of use already use one called SciTE, which is based on Scintilla. Crimson may be a bit more versitile though, adding coloring, like making both the XML and script parts colored, would require a major recompile of scintilla.
#17
Hmmm.. I though we could select the editor which MUSHClient uses for script editing. Well, at least the one you get when you edit plug-in.
Australia Forum Administrator #18
Yes indeed. The editor you choose in the Scripting configuration tab (if any) is used in preference to the inbuilt notepad, for both the world's script file, and editing plugins.
USA #19
Quote:
On the subject of editors, there was someone a while back that wanted an editor that would edit plugins but syntax colour the script part correctly...


Yes, Cedit can color different languages in one file, I used to remeber how to do this, I know its automatic for HTML. When I remeber how, I'll post here for you guys.

--Rakon