IonicWind Software

Aurora Compiler => General Discussion => Topic started by: Protected on May 25, 2006, 03:43:13 PM

Title: Noob questions #3
Post by: Protected on May 25, 2006, 03:43:13 PM
I'm looking into data manipulation right now. I found in the help two classes - CPointerList and CStringList - that seem to be... lists :P I noticed that CPointerList is used in the frags example, and since CStringList has the same methods (and also inherits from CList), I'll assume it works the same way. Now, I need to split a string in tokens and stuff the tokens somewhere, presumably in a CStringList. How do I go about splitting the string? I saw there are some IBasic-like methods, but LEFT$ and RIGHT$ seem to return HEAP. What exactly is HEAP? What do I do with it? Is there any chance of us getting something more 'strtok'-like? One of the things I like about PHP, for example, are the excellent explode and implode functions. Maybe they'd be good additions to Aurora?  :P
Title: Re: Noob questions #3
Post by: Parker on May 25, 2006, 04:45:07 PM
HEAP was also returned in IBasic, it's a type where the memory is automatically freed by the compiler. It's used when you want to return a string or a function from a subroutine, but can't pre-allocate it. The WHEAP type is used to return a wstring (UTF-16 string)
Title: Re: Noob questions #3
Post by: sapero on May 26, 2006, 03:25:06 AM
QuoteI need to split a string in tokens
look in nasm source :)

attached a console sample that displays colorized own source code ;D
(blue keywords not supported)

Input text file is mapped in memory, a token is a structure-list with pointers to strings in mapped memory, so no need to allocate new strings for every token.
Title: Re: Noob questions #3
Post by: Ionic Wind Support Team on May 26, 2006, 08:44:02 AM
HEAP is the same as string from the users point of view.  Just use the functions like you would in IBasic.

mystring = strleft(somestr, 10);

You can also use the string functions from the C runtime if you wish.
Title: Re: Noob questions #3
Post by: Protected on May 26, 2006, 12:08:55 PM
Thanks for the answers. I had no internet since yesterday so I couldn't reply earlier. I guess LEFT$ and RIGHT$ will have to work. Is there a way to declare a function so it's available absolutely everywhere? Like, I'd write global sub something (int a),int { blehblehbleh } and I'd be able to use it from inside any class, method, etc.
Title: Re: Noob questions #3
Post by: Parker on May 26, 2006, 02:30:16 PM
You'd have to use DECLARE EXTERN, but right now it doesn't adjust when it sees the function being defined, so you need to do something like I do:
the header file:
#ifndef __NOEXTERN__
declare extern someFunction( int x ),int;
#endif // !__NOEXTERN__


the implementation file:
#define __NOEXTERN__
#include "theheader.inc"
global sub someFunction( int x ),int
{
    // Do stuff here
}


another source file:
#include "theheader.inc"
...
    result = someFunction( 1 );
...
Title: Re: Noob questions #3
Post by: Ionic Wind Support Team on May 26, 2006, 06:31:52 PM
That only applies if your using an include file for the declare extern.  There is nothing wrong with using it in your source file either.
Title: Re: Noob questions #3
Post by: Protected on May 27, 2006, 07:26:48 AM
SO I go:

Quotedeclare extern someFunction (int x), int;

class A {
  declare someMethod (), int;
}

class B : A {
  declare B ();
}

B :: B () {
  Do stuff
}

A :: someMethod (), int {
  return someFunction (42);
}

global sub someFunction (int x), int {
  return x + 20;
}

global sub main () {
  int result;
  B test;
  result = test.someMethod ();
}

result would end with 52 in it?

Sorry for asking all this - I know I can try these things MYSELF, but while I'm not comfortable with the syntax yet I prefer to ask, because I don't want to risk deducing wrong facts out of my experiments. I'm pretty stupid.
Title: Re: Noob questions #3
Post by: Ionic Wind Support Team on May 27, 2006, 08:29:32 AM
declare extern someFunction (int x), int;

Would be in a different source file.  You don't need it to just use a function in the same file.  Only for projects
Title: Re: Noob questions #3
Post by: Protected on May 27, 2006, 08:37:45 AM
oh, so ANY global sub is accessible from ANYWHERE? Even inside inherited methods or other remote indirectly accessed stuff? That's where I wanted to get  ;D It's one of those interaction-between-oop-and-functional-programming things I'm not used to.
Title: Re: Noob questions #3
Post by: Ionic Wind Support Team on May 27, 2006, 08:42:10 AM
The procedural programming in Aurora is really no different than in was in IBasic Pro.  Just a bit easier since you can use the GLOBAL SUB keyword.

I think your confusing yourself with class methods.  Methods are also subroutines, just accessed differently and they are always global.
Title: Re: Noob questions #3
Post by: Protected on May 27, 2006, 08:45:27 AM
I never used IBasic Pro  :P
Thanks for your help.
Title: Re: Noob questions #3
Post by: J B Wood (Zumwalt) on May 27, 2006, 10:18:06 AM
I haven't had the use of this yet, so I haven't looked to see if its in there.
What about

value = stringlist
search = string
delimimiter=" "

value=Split(search,delimiter)

(high level not functional code, just use for example)

This should return for "blue white green", value(0)="blue", value(1)="white", value(2)="green"
Make sense?
Title: Re: Noob questions #3
Post by: Protected on May 27, 2006, 12:42:56 PM
That's how php's explode works, yes. Another way is string = token (string, delimiter, number). For example, a = token ("a b c", " ", 0) would return "a".
Title: Re: Noob questions #3
Post by: Ionic Wind Support Team on May 29, 2006, 11:52:01 PM
Quote from: Parker on May 26, 2006, 02:30:16 PM
You'd have to use DECLARE EXTERN, but right now it doesn't adjust when it sees the function being defined, so you need to do something like I do:

The easiest way is to just use #undeclare in the defining source file.  So for example if you have myfuncs.inc that had all of the functions declared as extern:

//myfuncs.inc
declare extern func1(),int;
declare extern func2(),float;
#define SOME_CONSTANT 111

//myfuncs.src
#include "myfuncs.inc"
#undeclare func1
global sub func1(),int
{
    return SOME_CONSTANT
}

Which is what I used to do in the old libraries.
Title: Re: Noob questions #3
Post by: Parker on May 30, 2006, 02:22:54 PM
Before the true release though, I think "DECLARE EXTERN"s should be removed if a GLOBAL SUB with the same name and parameters is found. Otherwise it just requires lots of extra commands and weird workarounds.
Title: Re: Noob questions #3
Post by: Ionic Wind Support Team on May 30, 2006, 03:12:11 PM
Nothing weird about it.  Same error in C.

And using the preprocessor is quite normal in this situation as well.