mIRC Home    About    Download    Register    News    Help

Print Thread
Other programming languages #112344 23/02/05 03:28 AM
Joined: Jan 2005
Posts: 37
S
Scratch Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Jan 2005
Posts: 37
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?

Re: Other programming languages #112345 23/02/05 03:36 AM
Joined: Jul 2003
Posts: 742
MTec89 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Jul 2003
Posts: 742
hahaha grin


http://MTec89Net.com
irc.freenode.net #MTec89Net
Re: Other programming languages #112346 23/02/05 03:42 AM
Joined: Nov 2003
Posts: 2,327
T
tidy_trax Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327
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.

Last edited by tidy_trax; 23/02/05 03:45 AM.

New username: hixxy
Re: Other programming languages #112347 23/02/05 03:45 AM
Joined: Jan 2005
Posts: 37
S
Scratch Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Jan 2005
Posts: 37
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?

Re: Other programming languages #112348 23/02/05 03:47 AM
Joined: Nov 2003
Posts: 2,327
T
tidy_trax Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327
The STL (Standard Template Library) has a few things available, but you'd still have to do a certain level of the parsing yourself.


New username: hixxy
Re: Other programming languages #112349 23/02/05 04:57 AM
Joined: Nov 2003
Posts: 2,327
T
tidy_trax Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327
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. :\


New username: hixxy
Re: Other programming languages #112350 23/02/05 11:55 AM
Joined: Apr 2004
Posts: 865
Sat Offline
Hoopy frood
Offline
Hoopy frood
Joined: Apr 2004
Posts: 865
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

Re: Other programming languages #112351 23/02/05 07:20 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
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.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: Other programming languages #112352 23/02/05 11:08 PM
Joined: Jan 2005
Posts: 37
S
Scratch Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Jan 2005
Posts: 37
Is Python really easy to learn? It sounds like a good choice for me...

Re: Other programming languages #112353 25/02/05 10:55 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
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.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: Other programming languages #112354 10/03/05 11:06 AM
Joined: Jul 2003
Posts: 40
H
HadS Offline
Ameglian cow
Offline
Ameglian cow
H
Joined: Jul 2003
Posts: 40
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;
}