class myclass extends _Struct and calling methods Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
smarq8
Posts: 69
Joined: 16 Jan 2016, 00:33

class myclass extends _Struct and calling methods

30 Dec 2019, 01:21

Hello
why I can not use any method after extending with _Struct?

Code: Select all

q := new myclass()
msgbox,% q.dim.2 "`n" q[]
q.tst() ;<---- not working


class myclass extends _Struct
{
	__new(){
		base.__new("int dim[3],int stepN,int dStepN,float* m")
		this.dim.1 := 2
		this.dim.2 := 4
		this.dim.3 := 6
	}
	tst(){
		msgbox,% "test"
	}
}
swagfag
Posts: 3276
Joined: 11 Jan 2017, 17:59

Re: class myclass extends _Struct and calling methods

30 Dec 2019, 06:46

because the method is getting overwritten/zeroed out/not cloned
as to why that is, gl sifting through this undebuggable mess, only @HotKeyIt can tell u
User avatar
TLM
Posts: 1561
Joined: 01 Oct 2013, 07:52
GitHub: TLMcode
Contact:

Re: class myclass extends _Struct and calling methods

30 Dec 2019, 07:21

:thinking:
as long as _Struct class with static array dim is declared,
calling test method works just fine here..
HotKeyIt
Posts: 1992
Joined: 29 Sep 2013, 18:35
Contact:

Re: class myclass extends _Struct and calling methods

30 Dec 2019, 07:52

Try this:

Code: Select all

q := new myclass()
msgbox,% q.dim.2 "`n" q[]
q.tst()


class myclass extends _Struct
{
	__new(){
		ObjRawSet(this,"´",new _Struct("int dim[3],int stepN,int dStepN,float* m"))
		this.dim.1 := 2
		this.dim.2 := 4
		this.dim.3 := 6
	}
	__Get(p*){
		return this["´"][p*]
	 }
	tst(){
		msgbox,% "test"
	}
}
smarq8
Posts: 69
Joined: 16 Jan 2016, 00:33

Re: class myclass extends _Struct and calling methods

30 Dec 2019, 11:50

Currently it seems to working. Now I'm curious why there is ObjRawSet() istead of this["´"] := new _Struct()? I've never use that earlier so I'm not quite sure whats the reason.

PS. it working but only partialy, as I try to stroe some data in stepN then it's stored as class variable instead of in struct

Code: Select all

#Include <_Struct>
q := new myclass()
q.dim.2 := 666
;q.dStepN := 123456
msgbox,% q.dim.2 "`n" q[] "`n" q.stepN
;q.tst()
;al(q)
mem_display(q[],0,10,1,"int") ;<--- see field 3
return


class myclass extends _Struct
{
	__new(){
		ObjRawSet(this,"´",new _Struct("int dim[3],int stepN,int dStepN,float* m"))
		this.dim.1 := 2
		this.dim.2 := 4
		this.dim.3 := 6
		this.stepN := 777 ;<--- it is stored as class variable, not in structure
	}
	__Get(p*){
		return this["´"][p*]
	 }
	tst(){
		msgbox,% "test"
	}
}

mem_display(memPtr,start,cnt,inc,dataType="double",round=6,splitLine=0){
	static ds := {uchar:1,char:1,uschort:2,short:2,uint:4,int:4,float:4,double:8,int64:8}
	dataSize := ds[dataType]
	str := ""
	loop,% cnt
	{
		n := A_Index-1
		offset := (start+n*inc)*dataSize
		val := numGet(memPtr+0,offset,dataType)
		if(splitLine>0 && mod(n,splitLine)==0){
			str .= "==============`n"
		}
		str .= round(A_Index-1+start) "`t" round(val,round) "`n"
	}
	msgbox,% str
}
HotKeyIt
Posts: 1992
Joined: 29 Sep 2013, 18:35
Contact:

Re: class myclass extends _Struct and calling methods  Topic is solved

30 Dec 2019, 14:52

Sorry, __Set needs to be defined as well here:

Code: Select all

class myclass extends _Struct
{
	__new(){
		ObjRawSet(this,"´",new _Struct("int dim[3],int stepN,int dStepN,float* m"))
		this.dim.1 := 2
		this.dim.2 := 4
		this.dim.3 := 6
		this.stepN := 777 ;<--- it is stored as class variable, not in structure
	}
	__Get(p*){
		return this["´"][p*]
	}
	__Set(k,v){
		return this["´"][k]:=v
	}
	tst(){
		msgbox,% "test"
	}
}
smarq8
Posts: 69
Joined: 16 Jan 2016, 00:33

Re: class myclass extends _Struct and calling methods

30 Dec 2019, 16:09

after few modyfications it's probably work fine but it's more redirect __set and __get rather than extends by itself. Thanks for any advice :thumbup:

here is my sample code:

Code: Select all

class _MATRIXS_
{
	__get(p*){
		return this["_"][p*]
	}
	__set(keys*){
		value := keys.pop() ; just for case where more than one keys are passed
		this["_"][keys*] := value
		return
	}
	;dataType := "float" ; it can not be used anymore because of __set()
	__new(shape){
		ObjRawSet(this, "dataType", "float")
		ObjRawSet(this, "dataSize", 4)
		ObjRawSet(this, "shape", [1,1,1])
		ObjRawSet(this, "_matrix", "")
		ObjRawSet(this, "ptr", "")
		ObjRawSet(this,"_",new _Struct("int dim[3],int elementsN,int stepN,int dStepN,float* m"))
		this.shape := shape
		this.dim.1 := shape.1
		this.dim.2 := shape.2
		this.dim.3 := shape.3
		this.elementsN := this.sizeOfShape(shape)
		this.stepN := 0
		this.dStepN := 0
		this.m[""] := class_memAlloc(this,"_matrix",this.elementsN*this.dataSize)
		this.fill(0)
	}
}

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], razvanm666 and 54 guests