Oxygen Basic
Programming => Problems & Solutions => Topic started by: Brian Alvarez on December 06, 2018, 10:03:36 PM
-
I noticed that, while this compiles and works fine:
'Generated with PluriBASIC 6.0.74371.0
$ filename "classes_on_macros.exe"
uses rtl32
class _newclass
public sys h
method constructor(int s)
h = getmemory(s)
print h
end method
method destructor()
freememory(h)
end method
function hPtr() as sys
print h
return h
end function
end class
MACRO ELEMENT_INIT(src, trg)
int i = sizeof(trg)
new _newclass buf(i)
src = buf.hPtr()
END MACRO
FUNCTION PBMAIN() AS INT
INT myvar
INT target
ELEMENT_INIT(myvar, target)
END FUNCTION
PBMAIN() ' invoke entry point
This does not compile:
'Generated with PluriBASIC 6.0.74371.0
$ filename "classes_on_macros.exe"
uses rtl32
class _newclass
public sys h
method constructor(int s)
h = getmemory(s)
print h
end method
method destructor()
freememory(h)
end method
function hPtr() as sys
print h
return h
end function
end class
MACRO ELEMENT_INIT(src, trg)
MACRO .readyup(src, trg buf, i, h)
int i = sizeof(trg)
new _newclass buf(i)
src = buf.hPtr()
END MACRO
END MACRO
FUNCTION PBMAIN() AS INT
INT myvar
INT target
ELEMENT_INIT.readyup(myvar, target)
END FUNCTION
PBMAIN() ' invoke entry point
It seems like when it is inside a child macro, the code does not recognize the class function hPtr().
-
By the way, i went away and implemented the child macros in PluriBASIC, and they work fine with Oxygen now.
However, i need to compile some child macros in raw Oxygen code, because i am changing the way the engine
clears variants when out of scope, to make use of the internal garbage collector instead of making my own.
No rush though. I know you are busy Charles. :)
-
Brian,
With the new o2, destructors are automatically invoked when objects go out of scope. (This does not apply to virtual objects created with 'new'). All you have to do is provide a destructor for the class.
-
Thanks charles.
In this update can i create and use class objects in a child macro?
-
Brian,
I found one problem with macro members. If you put a space between the macro name and the left bracket, this should make it locatable. but I will sort out this problem in the next few hours.