Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
adamandkate
Wanderer


Joined: 14 Oct 2009
Posts: 57

PostPosted: Sun Nov 20, 2011 1:40 pm   

advantages of lua?
 
Anyone able to tell me is there any advantages in using lua over zscript and should i start to learn it and convert my system over?

thanks
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Sun Nov 20, 2011 2:30 pm   
 
Personally, I think there is, in the long run. I don't have the script anymore, but I wrote a script in zscript that would tell me if a number was prime or not. It worked well for small numbers, but if you got too high a number, then CMUD would lock up, running the calculations. When I wrote it in Lua, those same numbers didn't give me any issues, and in fact, it took much larger numbers to cause the lock up to run back calculations.

Lua databases, in my opinion, are much easier to deal with, as well... especially if you have nested databases. The problem is saving variables across opening and closing of CMUD sessions. That's solved by saving the table to a file and then loading it with in onLoad event each session. Of course, you can also just save it to a variable, then load it each time from there, but I've had a few issues with variable corruption that I can't seem to pinpoint down so Zugg can fix them, so I go with saving them to a file.

In some cases, there may be minuscule differences between Lua and zscript. For me, Lua has become a bit easier to read than zscript, too. The concatenation is easier (though in zscript, you can use + in some places), you don't have to match braces with if/then/else statements (though you do have to match ifs and ends), and personally, the one that got me started on Lua in the first place, is the ability to make a much easier time difference script.

Note that this is not to say that zscript is useless. I still use zscript in a number of places, for now. Truthfully, Lua is a very powerful scripting language, and I'll probably continue to convert many more things over to Lua in the future simply because it does make my life quite a bit easier in the long run, in my opinion.
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Sun Nov 20, 2011 7:47 pm   
 
Quote:

Note that this is not to say that zscript is useless.


Zscript is not only not useless, it's the primary method of doing stuff in CMud. No other language is going to have an easier time accessing CMud stuff, and there won't be as many (if any) safeguards.
_________________
EDIT: I didn't like my old signature
Reply with quote
adamandkate
Wanderer


Joined: 14 Oct 2009
Posts: 57

PostPosted: Sun Nov 20, 2011 10:42 pm   
 
What about speed? I've been using mudlet that seems a lot faster. ┼┤ould cmud be faster if I used lua?
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Sun Nov 20, 2011 10:53 pm   
 
No, and Mudlet isn't faster. Not saying it's any slower, but it's definitely not > CMud. Keep in mind that if you're comparing zmud-imported scripts to Mudlet then you're not really anywhere near the top speed of CMud. While they work just fine in CMud, they're usually filled to the brim with inefficiencies.
_________________
EDIT: I didn't like my old signature
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Mon Nov 21, 2011 1:42 am   
 
I'm of the opinion that Lua is faster, again based on the test I described above. True, the test may be more about resources than anything, but it's also an increase of speed if I'm able to do calculations with larger numbers without CMUD freezing up.

For the most part, and for most everyday projects/scripts, you won't find any difference in speed. I seem to have a habit of writing resource-intensive scripts, so Lua is definitely an advantage for me. But if you're wondering if for k,v in pairs(table) do this end over 100 items will be quicker than #LOOPDB over the same 100 items, the answer will probably be no. You're more than welcome to run some delta timestamp tests for yourself, though. It's ultimately going to come down to the end user.

As for MUDclients, you truly can't gauge a client's speed based on another client's use of it. Some clients were built to specifically use that language, and therefore may inherently seem "faster." Other clients support the use of the language (CMUD, for example) and depending on what the client has to do to use that language, it can affect speed in various ways.
Reply with quote
Anaristos
Sorcerer


Joined: 17 Jul 2007
Posts: 821
Location: California

PostPosted: Mon Nov 21, 2011 2:55 am   
 
I think that since zscript is the "native" language of CMUD, it will always be the first choice when doing work within the client's API. In other areas Lua may be a better choice. For data persistence, there is a simple way to take care of that. Rather than use Lua's default global table _G, put all the variables you want to persist in one table and access them via the tablename.variablename method or use setenv, then at the end of the session just write the entire table out to a file using Lua.
What I like about using Lua is 1) COM programming is much simpler to implement because in Lua COM objects are tables. 2) I found that using Lua to handle the data from the GMCP triggers bypassed the contention problem that was causing color bleeding when writing to windows while in the trigger scope. In addition, I no longer have to schedule the writes. I can now put the data to the window as soon as I receive it without any collateral problems. 3) There are many Lua modules in existence that can be used to enhance the core language making it much more flexible in certain situations. Of notable mention is the implementation of parsing grammars found in the LPEG module. With this parsing API I've been able to bypass the problems that regex would have in implementing the same. If anyone is interested in writing context free grammars, look no further.
I don't think that I will ever quit using zscript as long as I use CMUD. I think that looking at Lua as replacement is putting it in the wong context. The fact that CMUD supports many scripting engines is a plus for the client. What that gives us is the ability to choose which language to implement our structures in the most efficient way.
Oh, I forgot to mention one nice bonus for using Lua. I can now work on my scripts without bringing CMUD up, instead I can use my favorite text editor any time I have the urge to code :)
_________________
Sic itur ad astra.
Reply with quote
ins0mnia
Novice


Joined: 23 Jan 2011
Posts: 42
Location: United States

PostPosted: Mon Nov 21, 2011 7:14 am   
 
Languages are just tools. You choose which is best for a task based on efficiency and comfort with it.

With that said, if you are interested in learning lua then rewriting existing zscript is a great way, but you're not likely to see noticeable differences in execution speed.
Personally I think lua usually looks cleaner and is more readable, but that's subjective.
Reply with quote
adamandkate
Wanderer


Joined: 14 Oct 2009
Posts: 57

PostPosted: Mon Nov 21, 2011 10:01 am   
 
I guess i wont bother then, im just trying to find ways to increase the speed of my scripts.

thanks for everyones comments
Reply with quote
ins0mnia
Novice


Joined: 23 Jan 2011
Posts: 42
Location: United States

PostPosted: Tue Nov 22, 2011 7:15 pm   
 
charneus wrote:
For the most part, and for most everyday projects/scripts, you won't find any difference in speed. I seem to have a habit of writing resource-intensive scripts, so Lua is definitely an advantage for me.


If you're having speed issues with specific code, it might be worth asking about it.
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Wed Nov 23, 2011 4:20 am   
 
ins0mnia wrote:
charneus wrote:
For the most part, and for most everyday projects/scripts, you won't find any difference in speed. I seem to have a habit of writing resource-intensive scripts, so Lua is definitely an advantage for me.


If you're having speed issues with specific code, it might be worth asking about it.


There's nothing to ask about. Plain and simple, it's resource-intensive. I'm far from a novice when it comes to writing scripts (not that you claim otherwise), but I do write scripts that hog up resources (which I could use #WAIT or #THREAD for, but rarely do). My prime number checker, for example - running the script in zscript took a while with larger numbers (say, 10k+). When I converted it over to Lua, those same large numbers were returned nearly instantly, and it took even larger numbers to cause Lua to say 'Hold on a minute there! I'm good, but not THAT good!'

In short, I know what works and what doesn't work, at least, for me. I've definitely used these forums quite a bit for some script help, but I'm always finding ways to increase the speed even marginally, and if I can write it in Lua, so be it. Thank you for the suggestion, however. It warms my heart to know that there are people out here still willing to assist others with scripts.
Reply with quote
ins0mnia
Novice


Joined: 23 Jan 2011
Posts: 42
Location: United States

PostPosted: Wed Nov 23, 2011 4:45 pm   
 
No sorry charneus, I was quoting you to say lua -can- improve speed in some cases because you already stated what I wanted to say. I meant adamandkate should ask if he has a specific script giving issues. I can see the reason for confusion, sorry.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net