Static function Link example

Started by Frank Brübach, January 30, 2025, 11:17:20 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Frank Brübach


thanks for your update charles, made this example to check and it's running fine,
you dont need at all the type block with declare functions.
second: you can change the static function with the link llike below, both ways are running ;)
regards, nice weekend, frank

'
' test o2 static function with link, 30-01-2025
'
'-------------------------------------------------------------------------------
declare function ptr myBatman(int x) as int 'our interface function

'
type abc
  'dim as int mi                'property
  'declare function f1() as int 'method
  'declare static function f2(int n) as int ' go
  'declare function f4(int n) as int 'method

end type

methods of abc
==============

dim static pp as int

' both static functions works

'static function f4(int x) as int,link @myBatman ' 1) linking to the outer function

static function f4(int x) link @myBatman as int ' 2) linking to the outer function

  pp=x
  print "f4 " x
end function

'function f1() as int
'  print "f1 " pp
'end function
'
end methods

myBatman(1357911)

' ends
['code]

Frank Brübach


'
 hey charles, I have done a new example with static function like my first issue
 works also very well
'
'
==========
module
==========

' works also without interface .. end interface, inner.. end inner
'
interface
  dim as int ptr abc
  declare function ptr bat(int x) as string
end interface


inner
  dim static pp as int
  int a : @abc=@a
  'static function f(int x) as string, link @bat
  static function f(int x) link @bat as string
  pp=x
  print "f4 " x

    return "ok"
  end function
  a=87654
end inner

==============
end module 'mm
==============
'
'test go
print abc   '
print bat(102040) 'ok


Charles Pegge

inner .. end inner makes the encapsulation. You can test this by trying to print a from the outside. It is hidden.

Frank Brübach

Yes thanks does Work Here value stays invisible outside the inner.. end inner Block

' test 3 invisible value outside -- inner.. end inner
' go
==========
module
==========

' works also without interface .. end interface, inner.. end inner
' but for this case the value ax outside is invisible
'
interface
  dim as int ptr abc
  declare function ptr bat(int x) as string
end interface


inner
  dim static pp as int
  int ax : @abc=@ax
  'static function f(int x) as string, link @bat
  static function f(int x) link @bat as string
  pp=x
  print "f4 " x

    return "ok"
  end function
  ax=87654
end inner

print "ax outside" + ax ' no result -> invisible :-) good!

==============
end module 'mm
==============
'
'test go
print "abc " + abc   '
print bat(102040) 'ok
' ends