mIRC Homepage
Posted By: Scratch Other programming languages - 23/02/05 03:28 AM
I enjoy scripting in mIRC in my free time, it's very fun and keeps me busy. I want to try coding in a regular compiled programming language, but I don't know which one is fun and easy like mIRC.

I was looking at some C++ source code, and some of the syntax looks similar to mIRC's syntax.

How much harder is C++ compared to mIRC scripting?
Posted By: MTec89 Re: Other programming languages - 23/02/05 03:36 AM
hahaha grin
Posted By: tidy_trax Re: Other programming languages - 23/02/05 03:42 AM
A lot of programming languages look similar to mIRC at first glance (Look at C, C++ and PHP for example) but they tend to only be similar in a few places, like using { }.

I'm sure a few people would disagree with me here, but C++ seems impossible for the first few months whether you have used mIRC scripting or not.

The hardest thing about going from mIRC to a low-level language like C++ is that you'll expect C++ to have things like left(), right(), mid(), replace(), remove(), etc., it doesn't.

Edit: getting used to data types is also a bitch when you use a language where everything is a string (Like mIRC) first.
Posted By: Scratch Re: Other programming languages - 23/02/05 03:45 AM
Quote:
The hardest thing about going from mIRC to a low-level language like C++ is that you'll expect C++ to have things like left(), right(), mid(), replace(), remove(), etc., it doesn't.


But isn't there "libraries" with functions like those available?
Posted By: tidy_trax Re: Other programming languages - 23/02/05 03:47 AM
The STL (Standard Template Library) has a few things available, but you'd still have to do a certain level of the parsing yourself.
Posted By: tidy_trax Re: Other programming languages - 23/02/05 04:57 AM
Here's a console example of gettok() and numtok() that accept characters as the third and second arguments instead of ascii numbers:

Code:
#include <cstdlib>
#include <iostream>
#include <windows.h>

using namespace std;

char *gettok(char *str, int n, char *c);
int numtok(char *str, char *c);

int main(int argc, char *argv[])
{
    cout << gettok("hello world", 2, " ") << endl;
    cout << numtok("hello world", " ") << endl;
    cin.get();
    return EXIT_SUCCESS;
}

char *gettok(char *str, int n, char *c)
{
     char stri[1024], *token;
     lstrcpy(stri, str);
     token = strtok(stri, c);
     for (int i = 1;token && (i < n);i++)
     {
         token = strtok(NULL, c);
     }
     return token;
}

int numtok(char *str, char *c)
{
 	char stri[1024], *token;
 	int n = 0;
 	lstrcpy(stri, str);
 	token = strtok(stri, c);
 	for (int i = 1;token;i++)
 	{
	    token = strtok(NULL, c);
	    n++;
 	}
 	return n;
}


There's probably better ways of doing both, but that's the best I could think of.

I made a new post because code looks awful with the extra spaces code tags add when you edit posts. :\
Posted By: Sat Re: Other programming languages - 23/02/05 11:55 AM
Just a sidenote, to show how hard this stuff actually is.. wink

Your gettok() implementation is not proper C code, as you're returning a pointer (token) to a buffer (stri) in the stackframe of the function being exited (gettok itself). The next called function (eg. the overloaded << operator, or numtok) may overwrite this buffer, resulting in the "token" pointer pointing to undefined data. You would have to allocate memory for the token, require the parent function to provide a pointer to a buffer for it, or use a global buffer variable, instead.

--------------------
Saturn, QuakeNet staff, #help.script
Posted By: starbucks_mafia Re: Other programming languages - 23/02/05 07:20 PM
Going straight from mIRC scripting to C++ is probably going to be too much. Learning C++ is quite simply an overwhelming experience if you don't already understand a lot of the concepts it utilises, which if you only know mIRC scripting, you almost certainly won't. I think you'd be far better off learning a higher level language first and working round to C++, possibly via C. Something like PHP or Python will introduce a lot of the concepts that you'll need to know before writing in C++, but in a way that doesn't feel like you've suddenly got to learn 100 things all at once just to do anything at all with the language. Not to mention that both PHP and Python have comprehensive help/references/tutorials available from their web-pages, whereas the scale of C++ and variety of C++ standards, pseudo-standards, and varying implementations of C++ compiler make it very difficult to find good documentation for a beginner that's directly relevant to your situation.
Posted By: Scratch Re: Other programming languages - 23/02/05 11:08 PM
Is Python really easy to learn? It sounds like a good choice for me...
Posted By: starbucks_mafia Re: Other programming languages - 25/02/05 10:55 PM
Well there's always going to be a learning curve when going from mIRC scripting's simplistic approach to any 'real' programming language, but I'd say Python is probably the easiest to make the transition with. The ability to write/run code interactively via the Python Shell is particularly useful when learning.
Posted By: HadS Re: Other programming languages - 10/03/05 11:06 AM
Quote:
Here's a console example of gettok() and numtok() that accept characters as the third and second arguments instead of ascii numbers:

Code:
#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
#include &lt;windows.h&gt;

using namespace std;

char *gettok(char *str, int n, char *c);
int numtok(char *str, char *c);
...

There's probably better ways of doing both, but that's the best I could think of.
Yes you’re right:
Code:
#include &lt;iostream&gt;
using namespace std;

char *gettok(char *subject, int num, const char sep, char *dszt);
int numtok(const char *subject, const char sep);

int main(void) {
	char buf1[64];
	cout &lt;&lt; gettok("hello world",2,' ',buf1) &lt;&lt; endl;
	cout &lt;&lt; numtok("hello world",' ') &lt;&lt; endl;
	cout &lt;&lt; gettok("This is a test",-3,32,buf1) &lt;&lt; endl;
	return 1;
}

char *gettok(char *subject, int num, const char sep, char *dszt) {
    if (!subject) return NULL;
    char *c, *d , *e;
    int i = 0; bool cont;
    if (num &lt; 0) { cont = true; num *= -1; } 
    else    cont = false;
    c = d = subject;
    while (*c == sep) c++; d = c;
    while (*c) {
        if (*c == sep) {
                i++;
                if (i == num) {
					e = d;
                    if (!cont) while (d &lt; c) *dszt++ = *d++;
                    else while (*d) *dszt++ = *d++;
                    *dszt = 0;
                    return e;
                }
                while (*c == sep) c++; d = c;
        }
        else c++; 
    }
    if (d &lt; c) { 
        i++;
        if (i == num) {
            e = d;
            while (*d)  *dszt++ = *d++;
            *dszt = 0;
            return e;
        }
    }
    return NULL;
}
int numtok(const char *subject, const char sep) {
	int res = 0;
	bool status = false;
Loop:
	if (*subject == sep) { status = false; }
	else if (*subject == 0) goto End;
	else if (status == false) {
		status = true;
		res++;
	}
	subject++;
	goto Loop;
End:
	return res;
}
© mIRC Discussion Forums