Functions in Types?

Previous topic - Next topic

Kitty Hello

Quote from: MrTAToad on 2010-May-04
Code (glbasic) Select
ok%=NETWEBGET(proxy$, "http://"+webAddress$+str$, port%, baseData.tempFile$)
And the C file is :
Code (glbasic) Select
ok=NETWEBGET(proxy_Str, CGStr("http:");
Ah, c'mon. That's not really bad, is it? :P
Oh dear. Now you see why I made this beta. You can't imagine what type of errors I got at the first run... I'll see if I can find time to fix that soon.

Schranz0r

OOOOOOOOOOOOOOOOOOOOOpppppps... that was to late yesterday :)
Sorry!
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Kitty Hello

OK, both fixed?

MrTAToad

Yey!  Arrays are working as is debug mode version :)

MrTAToad

#49
One thing that would be more efficient is that, instead of having "self" to access variables in a type, automatically assume that variable access will be done with variable from a type, and use something like "local." or "global." to access local or global variables.

Another thing :  A function defined in one type can't have the same name in another type, which is a shame...

In addition, you can't access a TYPE that hasn't already been compiled, which can be a problem if you want to pass a TYPE - you wouldn't all TYPE's in one file...

Aside from these problems, it seems to be working well, aside from the very tricky to diagnose "`__l_dbg_cont' was not declared in this scope" error.  At the moment, it seems to be caused by GLOBAL setup AS TSetup (as an example) in the main file or when a standard file is included, which is rather a problem :)

Kitty Hello

can you make small code pieces for these bugs?
If you need 2 files, just paste the 2nd file below the first - will be the same internally.

MrTAToad

The included file will generate the cont error...

[attachment deleted by admin]

MrTAToad

#52
With the latest beta, WHILE TRUE generates a Syntax Error on Windows XP, but not Windows 7  :blink:

Fixed now with that updated file...

It does appear the GLOBAL problem only occurs in debug mode...

MrTAToad

#53
There does seem to be a problem calling functions from a TYPE, for example :

Code (glbasic) Select
TYPE TBorder
x%;y%;width%;height%;image%;alpha // For displaying the border

FUNCTION Initialise_Border%:setup AS TSetup
self.x%=0
self.y%=0
self.width%=setup.ReturnHalfScreenWidth()
self.height%=setup.screenHeight%
self.image%=setup.spriteLoadData[0].idNumber%
self.alpha=0.0
ENDFUNCTION

FUNCTION Render_Border%:
ALPHAMODE self.alpha
STRETCHSPRITE self.image%,self.x%,self.y%,self.width%,self.height%
ENDFUNCTION
ENDTYPE


Generates a "call to undefined function : TSetup" error, even though ReturnHalfScreenWidth is present.  However, I can access the variables in TSetup okay

A simpler example is :

Code (glbasic) Select
TYPE TTest
FUNCTION moo%:
ENDFUNCTION
ENDTYPE

GLOBAL test AS TTest

test.moo()


Again, TTest (and TBorder) is in a seperate file.  It does look as though, whilst the class/type is being created, no functions are being created in it...

By the way, CODEFILE isn't quite correct :

Code (glbasic) Select
#define CODEFILE_Str() (DGStr("Test.gbas.gbas"))

Kuron

Having fun, Gernot :D

MrTAToad

For some reason, the following (which is all in the same main file), generates an error (error : wrong argument type : TYPE  is not declared) :

Code (glbasic) Select
TYPE TFont
FUNCTION moo:
ENDFUNCTION

FUNCTION moo2:
RETURN 1
ENDFUNCTION
ENDTYPE

LOCAL font AS TFont
LOCAL big

font.moo()
big = font.moo2()


The problem seems to occur when trying to assign big to the value from moo2 - remove that, and its okay, but unfortunately, is not the desired result.

Ian Price

I came. I saw. I played.

MrTAToad

Pretty much agree with it - generally, OOP over-complicates things and can make this much harder to read...

However, extended types in GLBasic however, make things much easier to re-use and update.

MrTAToad

Another slight problem found :

It appears function order matters when calling another function :

Code (glbasic) Select
TYPE TImage
Width
Height

FUNCTION MidHandleImage:
self.SetHandle(self.Width/2,self.Height/2); 
ENDFUNCTION

FUNCTION SetHandle:x,y
ENDFUNCTION
ENDTYPE


This generates the usual "call to undefined function : TImage" error message.  However, if you put SetHandle before MidHandleImage :

Code (glbasic) Select
TYPE TImage
Width
Height

FUNCTION SetHandle:x,y
ENDFUNCTION

FUNCTION MidHandleImage:
self.SetHandle(self.Width/2,self.Height/2); 
ENDFUNCTION
ENDTYPE


and all is fine...

Kitty Hello

Great find. I'll try to fix that one, too.