Page 1 of 3 123 LastLast
Results 1 to 10 of 23

Thread: how to call a user script function from TB_Module?

  1. #1

    how to call a user script function from TB_Module?

    How can I trigger an event or call a user defined script function from TB_Module ?
    use FreeSound
    hStream = CreateNewMP3Stream(NewFile))
    MP3StreamSetEndCallback(hStream, "MyCallBack")
    StartMP3Stream(hStream)
    ' ...
    sub MyCallBack(StreamID)
      printl "end of MP3 stream !"  + str$(StreamID)
    end sub
    
    thank you

    Joshy
    Last edited by D.J.Peters; 19-05-2013 at 14:34.
    (Sorry about my bad English.)

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: how to call a user script function from TB_Module?

    Hi Joshy,

    you can retrieve "pointer" to thinBASIC function using:
    fPTR = thinBasic_FunctionParseAndGetPtr(%FALSE)
    and then execute it using:
    [code=thinbasic]
    thinBasic_FunctionSimpleCall_ByPtr(fPTR)
    [/code]

    Please note the pointer is not true code pointer, due to thinBasic interpreted nature.
    Eros will know more.


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: how to call a user script function from TB_Module?

    Sorry to be so late in replying but currently I'm having heavy load at work.

    Petr already replied correctly.
    Use "fPTR = thinBasic_FunctionParseAndGetPtr(%FALSE)" to parse the name of the function indicated in script and get its thinBasic internal pointer.
    In your code, when you need to call that script function use "thinBasic_FunctionSimpleCall_ByPtr(fPTR)"

    If you need more info let me know.
    Eros

    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  4. #4

    Re: how to call a user script function from TB_Module?

    Thank you both
    i got callbacks with params working
    (after i created a new and complete import lib from thinCore.dll)

    Joshy
    Uses "FGLUT"
    ' multiply windows with callbacks
    
    CallBack Sub Reshape(ByVal WinID As Long, _
               ByVal W   As Long, _
               ByVal H   As Long)
     Local Ratio As Single          
     If H = 0 Or W = 0 Then Exit Sub
     If W>H Then
      Ratio=W/H
     Else
      Ratio=H/W
     End If  
     glViewport(0,0,w,h)
     glMatrixMode(%GL_PROJECTION)
     glLoadIdentity()
     gluPerspective(90.0, Ratio, 1.0, 100.0)
     glMatrixMode(%GL_MODELVIEW)
     If WinID=1 Then
      glClearColor(0.8,0.2,0.2,1)
      glColor3f(0.2,0.5,0.5)
     ElseIf WinID=2 Then
      glClearColor(0.2,0.8,0.2,1)
      glColor3f(0.5,0.2,0.5)
     Else
      glClearColor(0.2,0.2,0.8,1)
      glColor3f(0.5,0.5,0.2)
     End If
     
    End Sub
               
    CallBack Sub Display(ByVal WinID As Long)
     glClear(%GL_COLOR_BUFFER_BIT Or %GL_DEPTH_BUFFER_BIT)
     glLoadIdentity()
     gluLookAt(0.0, 1.0, 6.0, _ ' from
          0.0, 0.0, 0.0, _ ' to
          0.0, 1.0, 0.0)  ' up vector
     Select Case WinID
      Case 1:FGLUT_WireTeapot(4)
      Case 2:FGLUT_WireSphere(4)
      Case 3:FGLUT_SolidTeapot(4)  
     End Select 
     FGLUT_SwapBuffers
    End Sub
    
    CallBack Sub Keyboard(ByVal WinID As Long, _
               ByVal Key  As Long, _
               ByVal X   As Long, _
               ByVal Y   As Long)
     If Key=27 Then FGLUT_DestroyWindow(WinID)
    End Sub
    
    Dim i,WinIDs(3) As Long
    ' create 3 windows
    WinIDs(1)=FGLUT_NewWindowEx( 0, 0,400,400,"window 1")
    WinIDs(2)=FGLUT_NewWindowEx(410, 0,400,400,"window 2")
    WinIDs(3)=FGLUT_NewWindowEx( 0,438,810,200,"window 3")
    ' set for all windows callback's 
    For i=1 To 3
     FGLUT_SetWindow(WinIDs(i))
     FGLUT_SetDisplayCallback(Display)
     FGLUT_SetKeyboardCallback(Keyboard)
     FGLUT_SetReshapeCallback(Reshape)
    Next
    
    ' start your engines ;-)
    FGLUT_MainLoop
    
    Last edited by D.J.Peters; 19-05-2013 at 14:03. Reason: wrong code tag
    (Sorry about my bad English.)

  5. #5

    Re: how to call a user script function from TB_Module?

    Hi Joshy,

    I am conferring with Eros to bring the FreeBasic / thinCore SDK up to version 1.8.00. We have not given it any attention since August 2008 and much has been added since then. If all is well then it can be released with the next thinBasic beta.

    Strings (BSTR) and Extended Floats of course require special attention in FreeBasic modules, but I am not tempted to create a full set of wrapper functions since most TB modules only require a small number of conversions.

    Charles

  6. #6

    Re: how to call a user script function from TB_Module?

    hello Charles
    if assembler is your primary language then all other are not realy a problem.
    (i used C++ classes in VB6 or FreeBASIC in the past)

    With an uptodate def file you can create for any language a import lib.

    BSTR is simple an pointer on OLECHAR an FreeBASIC coder can use simple macros
    dim shared as EXT ext_null
    dim shared as EXT ext_value
    dim shared as BSTR bstr_name
    dim shared as BSTR bstr_value
    
    ' register string const
    #macro RSC(name,value)
     bstr_name = SysAllocStringByteLen(name,len(name))
     bstr_value = SysAllocStringByteLen(value,len(value))
     thinBasic_AddEquate bstr_name,bstr_value,ext_null,0
     SysFreeString bstr_name
     SysFreeString bstr_value
    #endmacro
    
    ' register long const
    #macro RLC(name,value)
     Long2Ext(@ext_value,value)
     bstr_name = SysAllocStringByteLen(name,len(name))
     bstr_value = 0
     thinBasic_AddEquate bstr_name,bstr_value,ext_value,0
     SysFreeString bstr_name
    #endmacro
    
    The biggest problem for FB user is
    the EXT 'ended data type has a wrong declaration in the thinCore.bi file
    is must be
    type EXT field=1
     dbl as double
     xtn as word
    end type
    
    with the wrong declare you can't link to the import lib
    of course EXT is 10 bytes (fldt fstpt) and not 12 bytes.

    But i know you're also a hardcore coder

    happy coding

    Joshy
    Last edited by D.J.Peters; 19-05-2013 at 14:06. Reason: wronge code tag
    (Sorry about my bad English.)

  7. #7

    Re: how to call a user script function from TB_Module?

    Hi Joshy,

    Yes I agree. With Asm handling Ext in Freebasic is easy. But to make all the thinCore functions work transparently in all cases we may be compelled to provide wrapper functions and work in Doubles. I cannot see how we can avoid this for FreeBasic (0.20) unfortunately. Ext numbers cannot be perfectly emulated in a freebasic expression.

    When Ext numbers are passed byval on the stack, the alignment is 12 bytes but within a PB / TB array they are packed to 10 bytes as you indicate, so I will change this.

    Thanks.

    Charles.

  8. #8

    Re: how to call a user script function from TB_Module?

    Quote Originally Posted by Charles Pegge
    I cannot see how we can avoid this for FreeBasic (0.20) unfortunately. Ext numbers cannot be perfectly emulated in a freebasic expression.
    you can create any new data type in FreeBASIC
    and overload missing operators like SQR,^,Mod ...

    or i don't understand your message

    Joshy
    type FLOAT80
     as byte bytes(9) ' 0-9 = 10 bytes
    end type
    
    type EXT
     as FLOAT80 Value
     declare constructor
     declare constructor(byref l as EXT)
     declare constructor(byval l as double)
     declare operator cast as string
    end type
    
    constructor EXT
     ' dummy constructor
    end constructor
    
    constructor EXT(byref l as EXT)
     dim as any ptr d =@value,s=@l.value
     asm
     mov eax,[s]
     fldt [eax]
     mov eax,[d]
     fstpt [eax]
     end asm
    end constructor
    
    constructor EXT(byval l as double)
     dim as any ptr p =@value
     asm
     fld qword ptr [l]
     mov eax,[p]
     fstpt [eax]
     end asm
    end constructor
    
    operator EXT.cast as string
     dim as any ptr p = @value
     dim as double d = any
     asm
     mov eax,[p]
     fldt [eax]
     fstp qword ptr [d]
     end asm
     return str(d)
    end operator
    
    Operator + (ByRef l As EXT, ByRef r As EXT) As EXT
     dim as EXT t
     dim as any ptr p = @t.value
     asm 
     mov eax,[l]
     fldt [eax]
     mov eax,[r]
     fldt [eax]
     faddp
     mov eax,[p]
     fstpt [eax]
     end asm
     Return t
    End Operator
    
    Operator - (ByRef l As EXT, ByRef r As EXT) As EXT
     dim as EXT t
     dim as any ptr p = @t.value
     asm 
     mov eax,[l]
     fldt [eax]
     mov eax,[r]
     fldt [eax]
     fsubp
     mov eax,[p]
     fstpt [eax]
     end asm
     Return t
    End Operator
    
    
    Operator / (ByRef l As EXT, ByRef r As EXT) As EXT
     dim as EXT t
     dim as any ptr p = @t.value
     asm 
     mov eax,[l]
     fldt [eax]
     mov eax,[r]
     fldt [eax]
     fdivp
     mov eax,[p]
     fstpt [eax]
     end asm
     Return t
    End Operator
    
    Operator * (ByRef l As EXT, ByRef r As EXT) As EXT
     dim as EXT t
     dim as any ptr p = @t.value
     asm 
     mov eax,[l]
     fldt [eax]
     mov eax,[r]
     fldt [eax]
     fmulp
     mov eax,[p]
     fstpt [eax]
     end asm
     Return t
    End Operator
    
    dim as EXT a = 1.0
    dim as EXT b = 3.0
    dim as EXT c = a+b*2 
    dim as EXT d = a/b
    print a,b,c,d
    
    sleep
    
    Last edited by D.J.Peters; 19-05-2013 at 14:11. Reason: wrong code tag
    (Sorry about my bad English.)

  9. #9

    Re: how to call a user script function from TB_Module?


    Wow! this is new to me. I have some catching up to do!

    Thanks Joshy.

    Charles

  10. #10

    Re: how to call a user script function from TB_Module?

    finaly you can create a libext.a and link it to gether with libthinCore.dll.a
    and the result could be libthinCoreFB.dll.a

    or you put in thinCore.bi #include "ext.bi" witch used #inclib "ext"

    from this point you can mix PB ext with FP ext.

    Joshy
    (Sorry about my bad English.)

Page 1 of 3 123 LastLast

Similar Threads

  1. CALL keyword with function name as string expression
    By ErosOlmi in forum Sources, Templates, Code Snippets, Tips and Tricks, Do you know ...
    Replies: 0
    Last Post: 07-09-2006, 16:16

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •