|
Post by bluatigro on Jul 17, 2020 4:04:38 GMT -5
i made the folowing @lib-test
global pi pi = atn( 1 ) * 4 function add( a , b ) add = a + b end function
and the folowing lib test
library "@lib-test.bas"
print " pi = " ; pi print " add pi , 5 = " ; add( pi , 5 )
lib and tester are in the same folder
but lib test con not find @lib-test.bas
idea : start every libname whit @ so you can recognise them easyer and you folder begins whit lib's
|
|
|
Post by bluatigro on Jul 17, 2020 7:20:14 GMT -5
is this posible ? b.bas
library "a.bas"
c.bas
library "b.bas"
|
|
|
Post by Carl Gundel on Jul 17, 2020 8:00:06 GMT -5
Here's how it works. The library is an object and you invoke functions against the library. Globals defined in a library are only visible to code in that library.
library "module.bas", #module z = #module getc() print z z$ = #module geta(); "+"; #module getb() print #module geta() + #module getb() print a+b #module output("this is a test") print #self debug$() print #module debug$() print "done"
Here is the library.
'module.bas
global a, b, c a = 3 b = 4 c = sqr(a^2+b^2) print c print "this is module.bas" open "example" for text as #t #t text("module here...") #t "!trapclose [quit]"; #t locate(20, 30, 120, 100) wait
[quit] print "Closing the window..." close #t wait
function output(txt$) #t txt$ end function
function closetxt() close #t end function
function geta() geta = a end function
function getb() getb = b end function
function getc() getc = c end function
Support for stepping into library functions in the debugger is not there yet.
In addition only functions can be called and not subs. At some point that will probably change.
|
|
|
Post by bluatigro on Jul 18, 2020 4:29:17 GMT -5
this works :
'' @lib-test.bas function add( a , b ) add = a + b end function function pi() pi = 3.1415926535897932384626433832795 end function
'' lib-test.bas library "@lib-test.bas" , #test
print " pi = " ; #test pi() print " add pi , 5 = " ; #test add( #test pi() , 5 )
this not : @lib-test.bas has no changes
'' lib-test.bas library "@lib-test.bas" , #test function show() print " pi = " ; #test pi() print " add pi , 5 = " ; #test add( #test pi() , 5 ) show = 1 end function
''lib test 2 library "lib-test.bas", #test2
''you can create a sub as function y = #test2 show()
so you can not make a chained lib system or do i somthing wrong ?
|
|
|
Post by Carl Gundel on Jul 18, 2020 16:50:08 GMT -5
this works : '' @lib-test.bas function add( a , b ) add = a + b end function function pi() pi = 3.1415926535897932384626433832795 end function
'' lib-test.bas library "@lib-test.bas" , #test
print " pi = " ; #test pi() print " add pi , 5 = " ; #test add( #test pi() , 5 )
this not : @lib-test.bas has no changes '' lib-test.bas library "@lib-test.bas" , #test function show() print " pi = " ; #test pi() print " add pi , 5 = " ; #test add( #test pi() , 5 ) show = 1 end function
''lib test 2 library "lib-test.bas", #test2
''you can create a sub as function y = #test2 show()
so you can not make a chained lib system or do i somthing wrong ? Not sure what purpose of this is? Usually a library of code is not supposed to know about the program that uses it.
|
|
|
Post by bluatigro on Jul 19, 2020 4:34:24 GMT -5
@carl
i m planning a lib system in whit a lib calls another lib examples : a 3dengine as low lib and a sphere lib as high lib and a line lib as high lib [ line does not use sphere ] and a triangle lib as high lib [ triangle does not use sphere or line ] and a raytrace lib as high lib
a openGL-1 lib as low lib [ for 352 ] and a bluaGL-1 lib as high lib [ for 352 ]
ofcourse i can put a low lib in a high lib but then those libs wil get verry big and i do not like typing the same thing twise
|
|
|
Post by bluatigro on Jul 19, 2020 5:55:06 GMT -5
@v3d.bas lib
'' bluatigro 17 jul 2020 '' vector 3d & color lib OOP style
global v3d.x , v3d.y , v3d.z '' global in a lib acts as a private property
function rgb( r , g , b ) rgb = r + g * 256 + b * 256 ^ 2 end function function v3d( x , y , z ) '' returns aways 0 ''constructor v3d.x = x v3d.y = y v3d.z = z end function function v3d.fromcolor( color ) ''constructor r = ( int( color ) and 255 ) / 256 g = ( int( color ) and 255 ) / 256 b = ( int( color ) and 255 ) / 256 q = v3d( r , g , b ) end sub function v3d.tocolor$() r = int( v3d.x * 256 ) and 255 g = int( v3d.y * 256 ) and 255 b = int( v3d.z * 256 ) and 255 v3d.tocolor$ = str$( r ) ; " " ; g ; " " ; b end function function v3d.uit( byref x , byref y , byref z ) '' = x = v3d.x y = v3d.y z = v3d.z end function function v3d.add( x1,y1,z1 , x2,y2,z2 ) '' + q = v3d( x1 + x2 , y1 + y2 , z1 + z3 ) end function function v3d.sub( x1,y1,z1 , x2,y2,z2 ) '' - q = v3d( x1 - x2 , y1 - y2 , z1 - z3 ) end function function v3d.div( x,y,z , f ) '' / q = v3d( x / f , y / f , z / f ) end function function v3d.mul( x,y,z , f ) '' * q = v3d( x * f , y * f , z * f ) end function function v3d.cross( x1,y1,z1 , x2,y2,z2 ) x = y1 * z2 - y2 * z1 y = z1 * x2 - z2 * x1 z = x1 * y2 - x2 * y1 q = v3d( x , y , z ) end sub function v3d.len( x,y,z ) v3d.len = sqr( x * x + y * y + z * z ) end function function v3d.dot( x1,y1,z1 , x2,y2,z2 ) v3d.dot = x1 * x2 + y1 * y2 + z1 * z2 end function function v3d.angle( x,y,z , nx,ny,nz ) l = v3d.len( x,y,z ) ln = v3d.len( nx,ny,nz ) d = v3d.dot( x,y,z , nx,ny,nz ) v3d.angle = acs( d / ( l * LN ) ) end function
v3d-test.bas
'' bluatigro 19 jul 2020 '' @v3d.bas lib test
library "@v3d.bas" , #v3d
WindowWidth = DisplayWidth WindowHeight = DisplayHeight global winw , winh winw = WindowWidth winh = WindowHeight
global red : red = #v3d rgb( 255 , 0 , 0 ) global blue : blue = #v3d rgb( 0 , 0 , 255 )
nomainwin
open "v3d test OOP style" for graphica as #m q = #v3d v3d.fromcolor( red ) q = #v3d v3d.uit( rr , rg , rb ) q = #v3d v3d.fromcolor( blue ) q = #v3d v3d.uit( br , bg , bb ) for x = 0 to winw q = #v3d v3d.mul( rr , rg , rb , x / winw ) q = #v3d v3d.uit( r1 , g1 , b1 ) q = #v3d v3d.mul( br , bg , bb , 1 - x / winw ) q = #v3d v3d.uit( r2 , g2 , b2 ) q = #v3d v3d.add( r1,g1,b1 , r2,g2,b2 ) #m "color " ; #v3d v3d.tocolor$() #m "down" #m line( x , 0 , x , winh ) #m "up" next x notice "ready" wait
what is not good in my open line ?
|
|
|
Post by Carl Gundel on Jul 19, 2020 13:25:14 GMT -5
@v3d.bas lib open "v3d test OOP style" for graphica as #m what is not good in my open line ? graphica is not a valid window type.
|
|
|
Post by Carl Gundel on Jul 19, 2020 13:28:35 GMT -5
@carl i m planning a lib system in whit a lib calls another lib examples : a 3dengine as low lib and a sphere lib as high lib and a line lib as high lib [ line does not use sphere ] and a triangle lib as high lib [ triangle does not use sphere or line ] and a raytrace lib as high lib a openGL-1 lib as low lib [ for 352 ] and a bluaGL-1 lib as high lib [ for 352 ] ofcourse i can put a low lib in a high lib but then those libs wil get verry big and i do not like typing the same thing twise There should be no problem at all having a program call a library which in turn calls another library. If it doesn't work now, I will figure out why and fix it. If you design your libraries properly there should not need to be any duplication of code between libraries.
|
|
|
Post by bluatigro on Jul 20, 2020 4:36:17 GMT -5
@v3d.bas
'' bluatigro 17 jul 2020 '' vector 3d & color lib OOP style
global v3d.x , v3d.y , v3d.z '' global in a lib acts as a private property
function rgb( r , g , b ) rgb = r + g * 256 + b * 256 ^ 2 end function function v3d( x , y , z ) '' returns aways 0 ''constructor v3d.x = x v3d.y = y v3d.z = z end function function v3d.fromcolor( color ) ''constructor r = ( int( color ) and 255 ) / 256 g = ( int( color ) and 255 ) / 256 b = ( int( color ) and 255 ) / 256 q = v3d( r , g , b ) end function function v3d.tocolor$() r = int( v3d.x * 256 ) and 255 g = int( v3d.y * 256 ) and 255 b = int( v3d.z * 256 ) and 255 v3d.tocolor$ = str$( r ) ; " " ; g ; " " ; b end function function v3d.uit( byref x , byref y , byref z ) '' = x = v3d.x y = v3d.y z = v3d.z end function function v3d.add( x1,y1,z1 , x2,y2,z2 ) '' + q = v3d( x1 + x2 , y1 + y2 , z1 + z3 ) end function function v3d.sub( x1,y1,z1 , x2,y2,z2 ) '' - q = v3d( x1 - x2 , y1 - y2 , z1 - z3 ) end function function v3d.div( x,y,z , f ) '' / q = v3d( x / f , y / f , z / f ) end function function v3d.mul( x,y,z , f ) '' * q = v3d( x * f , y * f , z * f ) end function function v3d.cross( x1,y1,z1 , x2,y2,z2 ) x = y1 * z2 - y2 * z1 y = z1 * x2 - z2 * x1 z = x1 * y2 - x2 * y1 q = v3d( x , y , z ) end function function v3d.len( x,y,z ) v3d.len = sqr( x * x + y * y + z * z ) end function function v3d.dot( x1,y1,z1 , x2,y2,z2 ) v3d.dot = x1 * x2 + y1 * y2 + z1 * z2 end function function v3d.angle( x,y,z , nx,ny,nz ) l = v3d.len( x,y,z ) ln = v3d.len( nx,ny,nz ) d = v3d.dot( x,y,z , nx,ny,nz ) v3d.angle = acs( d / ( l * ln ) ) end function
v3d-test.bas
'' bluatigro 20 jul 2020 '' @v3d.bas lib test
library "@v3d.bas" , #v3d
WindowWidth = DisplayWidth WindowHeight = DisplayHeight global winw , winh winw = WindowWidth winh = WindowHeight
global red : red = #v3d rgb( 255 , 0 , 0 ) global blue : blue = #v3d rgb( 0 , 0 , 255 )
nomainwin
open "v3d test OOP style" for graphics as #m q = #v3d v3d.fromcolor( red ) q = #v3d v3d.uit( rr , rg , rb ) q = #v3d v3d.fromcolor( blue ) q = #v3d v3d.uit( br , bg , bb ) for x = 0 to winw q = #v3d v3d.mul( rr , rg , rb , x / winw ) q = #v3d v3d.uit( r1 , g1 , b1 ) q = #v3d v3d.mul( br , bg , bb , 1 - x / winw ) q = #v3d v3d.uit( r2 , g2 , b2 ) q = #v3d v3d.add( r1,g1,b1 , r2,g2,b2 ) #m "color " ; #v3d v3d.tocolor$() #m "down" #m line( x , 0 , x , winh ) #m "up" next x notice "ready" wait
error : message not understood #selectSourceForFrame
i tryed debug to find the line but that did not work
|
|
|
Post by bluatigro on Jul 20, 2020 4:38:36 GMT -5
i hope that in the final version in the IDE the char's can be enlarged i can not see good what i m typing
|
|
|
Post by bluatigro on Jul 20, 2020 7:13:55 GMT -5
'' bluatigro 17 jul 2020 '' vector 3d & color lib OOP style
global v3d.x , v3d.y , v3d.z '' global in a lib acts as a private property
wait ''end here does not work also function rgb( r , g , b ) rgb = r + g * 256 + b * 256 ^ 2 end function function v3d( x , y , z ) '' returns aways 0 ''constructor v3d.x = x v3d.y = y v3d.z = z end function function v3d.fromcolor( color ) ''constructor r = ( int( color ) and 255 ) / 256 g = ( int( color ) and 255 ) / 256 b = ( int( color ) and 255 ) / 256 q = v3d( r , g , b ) end function function v3d.tocolor$() r = int( v3d.x * 256 ) and 255 g = int( v3d.y * 256 ) and 255 b = int( v3d.z * 256 ) and 255 v3d.tocolor$ = str$( r ) ; " " ; g ; " " ; b end function function v3d.uit( byref x , byref y , byref z ) '' = x = v3d.x y = v3d.y z = v3d.z end function function v3d.add( x1,y1,z1 , x2,y2,z2 ) '' + q = v3d( x1 + x2 , y1 + y2 , z1 + z3 ) end function function v3d.sub( x1,y1,z1 , x2,y2,z2 ) '' - q = v3d( x1 - x2 , y1 - y2 , z1 - z3 ) end function function v3d.div( x,y,z , f ) '' / q = v3d( x / f , y / f , z / f ) end function function v3d.mul( x,y,z , f ) '' * q = v3d( x * f , y * f , z * f ) end function function v3d.cross( x1,y1,z1 , x2,y2,z2 ) x = y1 * z2 - y2 * z1 y = z1 * x2 - z2 * x1 z = x1 * y2 - x2 * y1 q = v3d( x , y , z ) end function function v3d.len( x,y,z ) v3d.len = sqr( x * x + y * y + z * z ) end function function v3d.dot( x1,y1,z1 , x2,y2,z2 ) v3d.dot = x1 * x2 + y1 * y2 + z1 * z2 end function function v3d.angle( x,y,z , nx,ny,nz ) l = v3d.len( x,y,z ) ln = v3d.len( nx,ny,nz ) d = v3d.dot( x,y,z , nx,ny,nz ) v3d.angle = acs( d / ( l * LN ) ) end function
wait or end for al function's gives same error as last time @carl : how do i do this good ?
|
|
|
Post by Carl Gundel on Jul 20, 2020 9:27:47 GMT -5
i hope that in the final version in the IDE the char's can be enlarged i can not see good what i m typing Of course.
|
|