May 05, 2024, 08:31:48 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Noob questions #3

Started by Protected, May 25, 2006, 03:43:13 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

Protected

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

Parker

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)

sapero

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.

Ionic Wind Support Team

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.
Ionic Wind Support Team

Protected

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.

Parker

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 );
...

Ionic Wind Support Team

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.
Ionic Wind Support Team

Protected

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.

Ionic Wind Support Team

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
Ionic Wind Support Team

Protected

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.

Ionic Wind Support Team

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.
Ionic Wind Support Team

Protected

I never used IBasic Pro  :P
Thanks for your help.

J B Wood (Zumwalt)

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?

Protected

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".

Ionic Wind Support Team

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.
Ionic Wind Support Team

Parker

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.

Ionic Wind Support Team

Nothing weird about it.  Same error in C.

And using the preprocessor is quite normal in this situation as well. 
Ionic Wind Support Team