PDA

View Full Version : Class Libraries using Oxygen



Charles Pegge
01-08-2009, 12:04
Class Libraries

You can now create DLLs containing classes as well as SUBs an Functions. They are declared in much the same way:

class greeting lib `chatter.dll` alias `greeting`

followed by the rest of the class header.

On the library side, the classes must be marked export

class greeting alias `greeting` export

If no Alias is specified then the default is a lowercase match for the class name used.

Internally the methods table is passed from the library to the client at load time. This ensures that new classes can be derived from the the library classes.

The script below first generates a miinimal class library chatter.dll containing one class with 2 methods. The second parts of the script creates an object with it.


Oxygen Update: http://community.thinbasic.com/index.php?topic=2517




uses "oxygen","file"
dim src as string


'
'
'
' ###############
' ###################
' ### ###
' ### ### ###
' ### ## ## ###
' ### ## ## ###
' ### ## ## ###
' ### ## ## ###
' ### ## ## ###
' ### #### ## ###
' ### #### ###
' ### ###
' ### ###
' #############
' #########


'----------------------
'GENERATE CLASS LIBRARY
'======================

src ="
#basic

#file `chatter.dll`

'-------------------------------------
class greeting alias `greeting` export
'=====================================
method hello(n as string)
;
method goodbye(n as string)
/
a as long
end class


methods of greeting

method hello(n as string)
print `Hello ` n
end method

method goodbye(n as string)
print `Goodbye ` n
end method

end methods of greeting



sub finish()
terminate
end sub

"

'msgbox 0,o2_prep src
o2_basic src
if len(o2_error) then
msgbox 0, o2_error : stop
end if
o2_exec


' ##### ###### ###### ###### ######
' ######## ######### ######### ######### ###-*-####
' ## ## ## ## ## ## ## ## #########
' ## ## ## ## ## ## ## ## ##
' ## ## ## ## ## ## ## ## ##
' ## ## ## ## ## ## ## ## ##
' ## ## ## ## ## ## ## ## ##
' ## ## ## ## ## ## ## ## ##
' ## ########## ########## ########## ##########
' # ###### ###### ###### ######
'

'----------------------
'TEST THE CLASS LIBRARY
'======================

src="
#basic
'------------------------------------------------
class greeting lib `chatter.dll` alias `greeting`
'================================================
method hello(n as string)
method goodbye(n as string)
/
a as long
end class


dim g as greeting
g.goodbye `moon`
g.hello `earth`

xit:
terminate
"



file_save ("t.txt",o2_view src )
'msgbox 0,o2_prep src
o2_basic src
if len(o2_error) then
msgbox 0, o2_error : stop
end if
o2_exec
'msgbox 0,o2_error

Michael Hartlef
01-08-2009, 12:07
Nice, thanks for working further on Oxygen! I plan on using it with my next game which I will be at least prototyping in thinBasic.

Petr Schreiber
01-08-2009, 14:32
Hohoo,

that is pretty powerful Charles!

kryton9
10-08-2009, 05:15
Charles, this is really getting exciting, thanks for the news.

Mike, I will be excited to see what you come up with, good luck on your project!