|
Joined: Aug 2007
Posts: 72
Babel fish
|
OP
Babel fish
Joined: Aug 2007
Posts: 72 |
Hey, First off, I'm new to the mIRC message boards, so if this has been suggested already I must be doing something wrong because I've done about 7 different searches for this and found nothing... Seems like someone would have thought of this before... or the search here must not work correctly...
/hren Rename Hash Tables. /hren <table> [item] <new name> * renames <table> to <new name> * if [item] is specified, renames [item] to <new name>
and possibly...
/hcopy Copy item from 1 hash table to an other. /hcopy [-m] <table1> [item] <table2> [item2] * copies contents of <table1> to <table2> * if [item] is specified, copies [item] from <table1> to <table2>. * if [item2] is specified, copies [item] from <table1> to [item2] of <table2>. * if -m is used, creates <table2> if it doesn't exist. * if [item2] does not exist, creates [item2] automatically. * <table2> can be <table1>
mIRC Scripting: So easy a caveman could do it.
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,330 |
I'm not entirely sure why you'd rename a hash table that you created, but I suppose it's not a bad command to have. For the item names, it would just cut 2 commands down to 1 command, so I'm not sure why you'd do that.
As far as copying, that's not difficult to do without any other commands.
/hadd Table2 Item1_or_Item2 $hget(Table1,Item1).data
Invision Support #Invision on irc.irchighway.net
|
|
|
|
Joined: Aug 2004
Posts: 7,252
Hoopy frood
|
Hoopy frood
Joined: Aug 2004
Posts: 7,252 |
For renaming /hsave <table> <file>
/hmake <table2> <size>
/hload <table2> <file>
/hfree <table>
|
|
|
|
Joined: Aug 2007
Posts: 72
Babel fish
|
OP
Babel fish
Joined: Aug 2007
Posts: 72 |
I know this is probably not a practical everyday use example but for instance:
I've coded an IRC Server in mIRC Script for testing purposes and when a client connects to the scripted server i assign the new connection a temp name e.g. var %a = $+(Serv.Client.,$ticks) sockaccept %a I then create a hash table to store info about the new client. hmake %a 10 hadd %a ip $sock(%a).ip ect. ect. When the client sends the first nick command I then rename the client's socket to $+(Serv.Client.<nickname>) It would therefor be useful to simply rename the hash table to $sockname which is Serv.Client.Nickname
This is my example however i'm sure there are other irc (client) related examples as well.
mIRC Scripting: So easy a caveman could do it.
|
|
|
|
Joined: Aug 2007
Posts: 72
Babel fish
|
OP
Babel fish
Joined: Aug 2007
Posts: 72 |
I know there are workarounds. And the workarounds are how i currently handle these situations. However I think these commands would be simple to add into mIRC and think that there could be many practical script uses for these commands to make things easier / simpler / faster / better / more convenient.
For example if we didn't have /set, /unset, and %variables, we could use /writeini, and $readini (variables.ini). However Global Variables are easier / simpler / faster / better / more convenient.
The fact that i think these would be simple to implement with little effort is the only reason i suggest them. Otherwise I wouldn't bother and would suggest everyone use workarounds.
mIRC Scripting: So easy a caveman could do it.
|
|
|
|
Joined: Aug 2007
Posts: 72
Babel fish
|
OP
Babel fish
Joined: Aug 2007
Posts: 72 |
SladeKraven, it doesn't seem as if those posts have gotten anywhere. I don't quite understand how these commands could not seem useful to observers of these posts, whereas several scripting sites would show differently, just about all scripting help sites show a handful of sniplets that do these functions, there are tons of partially redundent commands in mirc that do far less than these commands would offer... I'm not entirely sure why you'd rename a hash table that you created, but I suppose it's not a bad command to have.
I've given my example above however apparently alot more people than me find it useful, hence all the sniplets. For the item names, it would just cut 2 commands down to 1 command, so I'm not sure why you'd do that. First off, it's a little more than 2 commands if you include error checking, Secondly I just thought it was only logical to include item renaming as part of the command. But besides that some scripts might contain alot of redundant item renaming thus cutting down the script by 50% or more. I would also like to point out the commands /hinc and /hdec, for the same reasons.. These commands cut down on 2 commands as well (not to mention tons of other commands which cut down on even less). And finally the true purpose of this command is to rename an entier hash table in such cases as the example I've given above, the item renaming is just a convenient side effect. As far as copying, that's not difficult to do without any other commands.
/hadd Table2 Item1_or_Item2 $hget(Table1,Item1).data
Same applies as above, there is also the possibility of what i call dynamic user templetes,in such case, one might want to copy entire hash tables. I could give an example but it's kinda lenghthy and might be confusing to most, so i won't bother. So anyway.. the current most common work around is to save the hash table as a file, then load into a new hash table.. This is obviously very inefficient. Also as DaveC pointed out on a previous post, this method does not work in such cases as the following:
bset &binvar 1000000 0 | hadd -mb table1 item1 &binvar
var %crlf = $crlf | hadd -m table1 item2 %crlf
var %num = 99 | hadd -mz table1 item3 %num
var %true = $true | hadd -mu10 table1 item4 %num
Final thought: All in all, I just don't understand why these commands are not already added. It seems to me that they should have been there since hash tables were introduced, I mean I cannot see how /hinc and /hdec made the cut, but /hcopy and /hren aren't there or even implimented as a switch of a current command. Hope to see these in the next version
mIRC Scripting: So easy a caveman could do it.
|
|
|
|
Joined: Dec 2002
Posts: 3,547
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 3,547 |
Unless Khaled has a public todo list only he can say whether or not it will be implemented. I'm not saying they aren't useful because I use Hash Tables quit often and wouldn't mind seeing it added. Along with a number of people on here.
Both of the commands you chose Hash Copying/Renaming were talked about 4 and a half years ago so I'm not sure if that's a hint or what, only time will tell but don't hold your breath.
|
|
|
|
Joined: Aug 2007
Posts: 72
Babel fish
|
OP
Babel fish
Joined: Aug 2007
Posts: 72 |
Post deleted by PhireCoder
mIRC Scripting: So easy a caveman could do it.
|
|
|
|
Joined: Jul 2003
Posts: 655
Fjord artisan
|
Fjord artisan
Joined: Jul 2003
Posts: 655 |
Do you always bitch when somebody offers you an informative & educated opinion based on historical facts?
I think /hcopy is useless give that you can do it in a single command with /hadd already.
I think that /hrename would be quite useful, it an easy alias to script, however saving to file and reloading can become quite a significant waste of resouces/cpu cycles/etc and potentially slow a script down quite a bit. Much cleaner to just change one simple value in memory.
"Allen is having a small problem and needs help adjusting his attitude" - Flutterby
|
|
|
|
Joined: Nov 2006
Posts: 1,559
Hoopy frood
|
Hoopy frood
Joined: Nov 2006
Posts: 1,559 |
My latest suggestion has zero replies so far; now I could suppose what I suggested was too ingenious or too stupid, or just too bland or all opinions are ambiguous... ...but I don't! Wanna swap places with me? EDIT: side note: I like the hren, too
Last edited by Horstl; 28/08/07 11:47 PM.
|
|
|
|
Joined: Aug 2007
Posts: 72
Babel fish
|
OP
Babel fish
Joined: Aug 2007
Posts: 72 |
Post deleted by PhireCoder
Last edited by PhireCoder; 29/08/07 01:41 AM.
mIRC Scripting: So easy a caveman could do it.
|
|
|
|
Joined: Dec 2002
Posts: 3,547
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 3,547 |
!!!!! (Message to the future - Yeah you reading this post dated back 4 and a half years ago in 2007 - Don't bother reposting this suggestion, It's useless) !!!!!
Most people wouldn't repost anyway if they had the common sense, on the other hand that's the most useful thing you've come out with. Well Done.
|
|
|
|
Joined: Aug 2007
Posts: 72
Babel fish
|
OP
Babel fish
Joined: Aug 2007
Posts: 72 |
Post deleted by PhireCoder
mIRC Scripting: So easy a caveman could do it.
|
|
|
|
Joined: Dec 2002
Posts: 3,547
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 3,547 |
And how did you come to that conclusion? You haven't seen a picture of me. Anyways, even if I was what does that have to do with any of the above?
|
|
|
|
Joined: Aug 2007
Posts: 72
Babel fish
|
OP
Babel fish
Joined: Aug 2007
Posts: 72 |
Post deleted by PhireCoder
mIRC Scripting: So easy a caveman could do it.
|
|
|
|
Joined: Dec 2002
Posts: 2,962
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,962 |
OK I'm thinking both of you need to stop if you intend to salvage any shred of dignity out of this thread.
The suggestion has been made, I'm sure Khaled will read it and consider it. Yes, there's no reason not to suggest it again after x many years since the last time. Yes, it makes sense to post any previous threads - hopefully to save everyone going over the same ground again and in case any good points were made for or against a feature. Yes, it can make sense to show how something can be scripted especially if it's quite simple, but no that in itself is not necessarily enough reason to mean something shouldn't be added to mIRC as a feature.
There, everything covered. So now can we all please get back to discussing the feature itself instead of this pathetic arguing?
Spelling mistakes, grammatical errors, and stupid comments are intentional.
|
|
|
|
Joined: Aug 2007
Posts: 72
Babel fish
|
OP
Babel fish
Joined: Aug 2007
Posts: 72 |
OK, back to the topic... In this post I would like to show exactly how these commands would function for anyone interested... You can use these aliases until they are implemented as internal commands. Advanced Users and/or Anyone not interested in these commands, may simply disregard this post. Note that while these aliases function perfectly they are not nearly as efficient as built-in commands. Also I am aware that using /hsave and /hload instead of while loops may be more efficient, however that method doesn't work properly in certain situations. These aliases include error handling. Command: /hren Info: Renames hash tables or hash table items. Syntax: /hren <table> [item] <new name>
alias hren {
if (!$2) echo $color(info) -ae * /hren: insufficient parameters
elseif (!$hget($1)) echo $color(info) -ae * /hren: no such table $+(',$1,')
elseif ($3) {
if (!$hfind($1,$2)) echo $color(info) -ae * /hren: no such item $+(',$2,')
else {
hadd $1 $3 $hget($1,$2)
hdel $1-2
}
}
elseif ($2) {
var %a = $hget($1,0).item
hmake $2 $hget($1).size
while (%a) {
hadd $2 $hget($1,%a).item $hget($1,%a).data
dec %a
}
hfree $1
}
}
Command: /hcopy Info: Copies hash tables or hash table items. Syntax: /hcopy <table1> [item1] <table2> [item2]
alias hcopy {
if (!$2) echo $color(info) -ae * /hcopy: insufficient parameters
elseif (!$hget($1)) echo $color(info) -ae * /hcopy: no such table $+(',$1,')
elseif ($3) {
if (!$hfind($1,$2)) echo $color(info) -ae * /hcopy: no such item $+(',$2,')
elseif ($4) hadd -m $3-4 $hget($1,$2)
else hadd -m $3 $2 $hget($1,$2)
}
else {
var %a = $hget($1,0).item
if (!$hget($2)) hmake $2 $hget($1).size
while (%a) {
hadd $2 $hget($1,%a).item $hget($1,%a).data
dec %a
}
}
}
mIRC Scripting: So easy a caveman could do it.
|
|
|
|
Joined: Aug 2007
Posts: 72
Babel fish
|
OP
Babel fish
Joined: Aug 2007
Posts: 72 |
oops messed up on above /hren command... here's the fixed version...
alias hren {
if (!$2) echo $color(info) -ae * /hren: insufficient parameters
elseif (!$hget($1)) echo $color(info) -ae * /hren: no such table $+(',$1,')
elseif ($3) {
if (!$hfind($1,$2)) echo $color(info) -ae * /hren: no such item $+(',$2,')
else {
hadd $1 $3 $hget($1,$2)
hdel $1-2
}
}
elseif ($hget($2)) echo $color(info) -ae * /hren: table name already in use $+(',$2,')
else {
var %a = $hget($1,0).item
hmake $2 $hget($1).size
while (%a) {
hadd $2 $hget($1,%a).item $hget($1,%a).data
dec %a
}
hfree $1
}
}
mIRC Scripting: So easy a caveman could do it.
|
|
|
|
Joined: Oct 2003
Posts: 3,918
Hoopy frood
|
Hoopy frood
Joined: Oct 2003
Posts: 3,918 |
right but when using in a controlled environment (ie. your own scripts) 80% of the error checking is unnecessary, turning the snippet into essentially a one-(technically, two)-liner:
alias hcopy { var %f = $+($1,$ticks) | hsave -bu $1 %f | hmake $2 | hload -b $2 %f | .remove %f }
alias hren { hcopy $1 $2 | .hdel $1 }
This, however, is not how renaming *should* be done. It *should* be done by just changing the symbol name in the script engine's symbol table so that no copying is necessary at all. Renaming the symbol name would mean improved performance, which is why I believe the suggestion is good on the grounds that it is not possible to do (properly) via script-- NOT because it will reduce your script's line count by ~7 lines. hcopy could also be better implemented at the C level simply by a memcpy() of the hash structure, but of course everything could be better implemented in C, so I won't delve into that. ps. you'll notice I used hsave/load in my implementation. You claim that it does not work properly in certain situations-- manually using /hadd will work improperly in many more situations, specifically with binary data, which your alias cannot get out. Technically, my alias probably won't maintain "unset" information or any items set with -z. unset information can be maintained by looping with and adding with
hadd -mbu $+ $hget($1,%i).unset $2 &tmp
but this method still will not maintain the -z information. This is yet another reason this suggestion is useful, since you can't accurately copy a hash table via script anyway, no matter how many lines it takes. Why you would need to copy or rename a table after creating it is another question though, but I won't even bother to ask. I don't buy the "using the name to store the status" story, by the way-- that can much more easily just be done with a "status" item in the table, and it makes more implementation sense too.
- argv[0] on EFnet #mIRC - "Life is a pointer to an integer without a cast"
|
|
|
|
|