Call type-functions At data immediately
issueid=459 31-03-2014 11:22
thinBasic MVPs
Number of reported issues by ReneMiner: 83
Call type-functions At data immediately
omit unnecessary local pre-overlay & selection-routines

The idea is to call functions of a type on data by passing a pointer where to expect the "Me-variable".

CallAt pData [As t_myType| Like "t_myType"], FunctionName ([PARAMETERS]) [To Result]

'CallAt: call a type-function but data-position passed as pointer and not as variable-name
'pData: pointer to current element ( =VarPtr(myVar) )
'FunctionName: the name of a function as defined inside type-definition
'Parameters: parameters as t_myType.FunctionName would expect


It would allow to call dynamically different types functions (f.e. within a loop) which is currently not possible without complicated and resource-consumpting pre-selection and would NOT need a local overlay-variable for each of all used types because it can not change the type within the same function and which just gets used to create another overlay "Me" in the actual called function then -

so why not have a way to call a type-function at some data as/like some type directly?
Issue Details
Issue Number 459
Issue Type Feature
Project thinBasic
Category Core engine (thinCore.dll)
Status Suggested
Priority 7
Suggested Version 2.0
Implemented Version (none)
Milestone (none)
Votes for this feature 2
Votes against this feature 0
Assigned Users (none)
Tags (none)




17-04-2014 10:59
thinBasic MVPs
Already thinking of another syntax:
Call At pData, "t_MyType.myFunction"[([Parameters])]  [To Result]
to set the Me-overlay to the position found in pData...

19-04-2014 17:14
Super Moderator
Hi Rene,

do I understand correctly, that the functionality is shorter equivalent of the following?:
DWord pMe = varPtr(me)
...

DIM refMe AS t_MyType At pMe
refMe.FunctionName([PARAMETERS])

Petr

19-04-2014 17:36
thinBasic MVPs
There is no Me in the first place. Perhaps pMe in your code could be a pointer to something else...


CALL AT would not need some local pre-overlay (second line of your code) before the call
It's some equivalent for these steps:


  ' myDataPtr can be heap-pointer, a simple stringpointer or pointer to a dictionary-bucket, so no variable. 
  
Global Function_CalledFrom As Dword = myDataPtr

  ' Function_CalledFrom now contains a position where to find data which shall be
  ' ME in the following called type-function

Call_IfExists "t_myType.MyFunction" [([Parameters])] [To Result]


' and this would be the type-function which is not called from a variable now (as line 3 in your code), so Me is not dimensioned anyway:
Function t_myType.MyFunction ()

   If Function_CalledFrom Then
    Local Me as t_myType At Function_CalledFrom
    Function_CalledFrom = 0
   Endif
'...
End Function
It would allow to call type-functions within a loop without having to select the kind of variable for some pre-overlay - very dynamic because can be any type and does not need a virtual variable (as refMe in your code) for all possible types previously. Perhaps you remember my Items-example-(post above yours):
I try to call same named functions of different variable-types within some loop just by telling the function where to find Me so not to have to select which pre-overlay-variable to use now nor to have to use any overlay at all.
The type is already part of the functions name and anyway its "parent".

expressed another way, how I would have to use it current possible methods- example:
' within some loop...
Select Case LCase$(TypeOfMyData) 

Case "t_triangle"
  Dim vTriangle As t_Triangle At myDataPtr
  vTriangle.Render()
Case "t_rect"
  Dim vRect As t_Rect At myDataPtr
  vRect.Render()
Case "t_circle"
  Dim vCircle Like TypeOfMyData At myDataPtr
  vCircle.Render()

'...
very cumbersome and absolutely non-dynamic since virtual overlay can not change type here, so I would need one overlay-variable for every type and have to add another case for each new type.

I would like to do it this simple way:
Call At myDataPtr, TypeOfMyData & ".Render"()

20-04-2014 16:43
Super Moderator
I add my vote for this!


Petr

28-04-2014 10:59
thinBasic MVPs
...deleted...

29-04-2014 15:39
thinBasic MVPs
Now getting crazy, already possible to use the following call:

Call By.Pointer dataPtr, "t_Type.someFunction" [([Parameters])] [To Result]
How?

Check this example (runs of course)

#MINVERSION 1.9.12.0

Uses "console"  

Type t_CallByPtr
  pData   As DWord
  Pointer As Function
End Type

Function t_CallByPtr.Pointer(ByVal pData As DWord, _
                             ByVal sFunction As String _
                            ) As DWord

  Me.pData = pData
  Return Function_GetPtr(sFunction)
   
End Function  

Global By As t_CallByPtr
 
' ---------------------------------------------------------                     
' example-type to use here
Type t_myType
  A As Long
  B As Long
  AddUp As Function
End Type
 
Function t_myType.AddUp(Optional ByVal C As Long) As Long
  
  ' have to add this to every type-function 
  If By.pData Then
    Local Me As t_myType At By.pData
    By.pData = 0
  EndIf
   
  ' now the function:   
  Return Me.A + Me.B + C

End Function
'---------------------------------------------------------

' some arbitrary data matching our type 
Dim dataPtr As DWord = HEAP_AllocByStr(MKL$(12, 34))
 
Dim lResult As Long


'  ##################################################################
' ##                                                                ##
     Call By.Pointer dataPtr, "t_myType" & ".Addup" (-4) To lResult
' ##                                                                ##
'  ##################################################################


PrintL "result : " & lResult
 
PrintL $CRLF & Repeat$(lResult, Chr$(lResult))
PrintL $CRLF & "Any key to end"
WaitKey

07-05-2014 14:31
thinBasic MVPs
my project really depends on this:

otherwise I can not use type-functions on my data and not have the benefits of using EXTENDS together at once.

It needs a special call to a type-function that creates the Me-variable at some address if the type-function gets not called from a variable directly.

I can pass type (string), function-name (string), pointer to Me and of course the functions awaited parameters. See above - not very difficult, my problem is I would have to add the part
If By.pData Then
  Local Me as [parenting type] At By.pData
  By.pData = 0
EndIf
to each and every type-function - or I would have to use very "unclean" code - which is not very TOP (Type Oriented Programming)

10-05-2014 12:05
thinBasic MVPs
I re-wrote the script once again - maybe is an idea concerning the way of how to dim Me to the correct type...

#MINVERSION 1.9.12.0
 
Uses "console" 
 
Type t_CallByPtr
  pData   As DWord 
  sType   As String
  Pointer As Function
End Type
 
Function t_CallByPtr.Pointer(ByVal pData As DWord,     _
                             ByVal sType As String,    _
                             ByVal sFunction As String _
                            ) As DWord
 
  Me.pData = pData  
  Me.sType = sType
  
  Return Function_GetPtr(sType & "." & sFunction)
    
End Function 
 
Global By As t_CallByPtr

' ---------------------------------------------------------                     
' example-type to use here
Type t_myType
  A As Long
  B As Long
  AddUp As Function
End Type
  
Function t_myType.AddUp(Optional ByVal C As Long) As Long
   
  ' have to add this to every type-function currently:

  If By.pData Then
' # # # # # # # # # # # # # # # # # # # # # # # #

    Local Me Like By.sType At By.pData  '                    << << <<

' # # # # # # # # # # # # # # # # # # # # # # # #
    By.pData = 0
  EndIf
'- - - - - - - - -     
  ' now the function:   
  Return Me.A + Me.B + C
 
End Function
'---------------------------------------------------------
' Testing:

' some arbitrary data matching our type 
Dim dataPtr As DWord = HEAP_AllocByStr(MKL$(-43,21))
  
Dim lResult As Long
 
 
'  *******************************************************************
' **                                                                 **
      Call By.Pointer dataPtr, "t_myType", "AddUp" (64) To lResult
' **                                                                 **
'  *******************************************************************
 
 
PrintL "result : " & lResult
  
PrintL $CRLF & Repeat$(lResult, Chr$(lResult))
PrintL $CRLF & "Any key to end"
WaitKey

04-07-2014 10:02
thinBasic MVPs
I'm stuck again :(

really need this feature

...ok not so urgent at the moment... more urgent were a private scope ( as udt-members, perhaps like udt-subsets that can only be accessed by Me...?) see Petrs suggest somewhere in depth of support-section)

20-09-2014 11:29
thinBasic MVPs
see you were really busy the last days... even if i don't need it currently that urgent it were great to have the possibility to call a type-function on a pointer. of course no "inheritance" possible then

30-04-2021 09:00
thinBasic MVPs
... i think the issue is solved through keyword ANYTYPE in the meantime.
Can be marked as "Done" by implementation of another feature

+ Reply