Results 1 to 8 of 8

Thread: New to interpreter type questions.

  1. #1

    New to interpreter type questions.

    I have written programs with PureBasic and realBASIC but thinBasic is the first time I have worked with an interpreter - I have a couple of questions:

    Is the interpreter able to run numerous programs simultaneously, or should you have an installation for each application you create?

    Now for the question that suddenly got me excited about using an interpreter (oh, how I hope the answer is 'yes'...):
    Is it possible to write a program that dynamically writes another program at runtime and then calls the interpreter to run that too?

    Thanks

  2. #2

    Re: New to interpreter type questions.

    Hi Steve,

    welcome on board. You can run numerous scripts at the same time but they can't communicate with each other.
    thinBasic Scripts can be bundled to an exe. If you bundled, they don't need thinBAsic installed on a computer.
    If run them as a script (which can be obfuscated), then only one thinBASIC has to be installed.

    And yes, you can run scripts from other scripts, but like I said, they can't communicate with each other. I wish they could.

    If you have other questions, then please feel free to ask them.

    Michael

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

    Re: New to interpreter type questions.

    Ciao Steve and welcome at thinBasic community.

    First question: yes.
    You can execute as many scripts as you need. Every execution will be handled by a different process. Just try by yourself executing many scripts by double clicking on them in Windows shell or by any other way.

    Second question: yes.
    The interpreted nature of thinBasic will let you write script on the fly, save them on temp files and invoking thinBasic ingine to execute them. I will prepare a quick example later.

    Ciao
    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
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: New to interpreter type questions.

    EDIT: Too late

    Hi Steve,

    welcome to thinBASIC!

    I will try to answer your questions, although better to wait for official reply from Eros ( Olmi ) or Roberto ( Bianchi ).
    Is the interpreter able to run numerous programs simultaneously, or should you have an installation for each application you create?
    If this means "can I run multiple scripts at the same time with single thinBASIC installation" then answer is "Yes"

    One very nice feature of thinBASIC is its thinBundle - you can create EXE package of your script, and distribute this file further as you want ( and run in as many instances as you want ). So even not required to have thinBASIC installed on target platform.

    Is it possible to write a program that dynamically writes another program at runtime and then calls the interpreter to run that too?
    There are many ways of doing such a tricks. One is more "limited", and serves to evaluate string expressions, have a look at EVAL module in help file. So you can get formula and evaluate it on the fly.
    [code=thinbasic]
    USES "EVAL"

    msgbox 0, EVAL_MATH("(5*3+2/5)^2")
    [/code]

    Second way is to create script on the fly, and shell it:
    [code=thinbasic]
    ' -- We need FILE module to write file, OS module to shell it
    uses "FILE"
    USES "OS"

    ' -- Script contents
    dim Script as string = "MSGBOX 0, ""Just very basic script"""+$CRLF+ _
    "ALERT(""That is all for now"", ""Thanks for trying"")"

    ' -- Write it to file
    FILE_SAVE(APP_SCRIPTPATH+"\MyCustomScript.tBasic", Script)

    msgbox (0, "Ok, file saved"+$CRLF+"All what you will see from now is from the other script file", %MB_ICONINFORMATION)

    ' -- Following line does two things
    ' -- APP_PATH+"thinBASIC.exe" returns correct thinBASIC install path and adds filename
    ' -- ... and it runs the script, created on the fly
    OS_SHELL(APP_PATH+"thinBASIC.exe"+$SPC+APP_SCRIPTPATH+"\MyCustomScript.tBasic", %OS_WNDSTYLE_NORMAL, %OS_SHELL_SYNC)

    msgbox (0, "Now we are back in main script file, hope you liked it, it will end now", %MB_ICONINFORMATION)
    [/code]

    The third way would be to create EXE on the fly from script, and shell it.

    Other advantage of thinBASIC being interpreted is that you can call functions by name specified on the run-time, try following script:
    [code=thinbasic]
    ' -- We will use console
    uses "Console"

    ' -- Text on screen
    Console_WriteLine("Welcome!, enter one of the following words to get greeted in selected language:")
    Console_WriteLine("ENGLISH")
    Console_WriteLine("GERMAN")
    Console_WriteLine("ITALIAN")
    Console_Write("Your choice ? ( for example ITALIAN ): ")

    ' -- Retrieving reply
    dim Reply as string
    reply = console_Readline()

    ' -- Now if entered was "GERMAN", it will call GreetMe_German, if "ITALIAN" it will call GreetMe_Italian ...
    CALL "GreetMe_"+Reply()

    console_WaitKey

    sub GreetMe_English()
    Console_WriteLine("--> Hi")
    end sub

    sub GreetMe_German()
    Console_WriteLine("--> Hallo")
    end sub

    sub GreetMe_Italian()
    Console_WriteLine("--> Ciao")
    end sub
    [/code]

    Hope I made it clear, but as I said, better to wait for examples and samples from the masters


    Bye,
    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

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

    Re: New to interpreter type questions.

    Hey Petr, your reply is so complete ... that my reply embarrassed me :-[

    Thanks a lot.
    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

  6. #6

    Re: New to interpreter type questions.

    Hello everyone and thank you for being so welcoming.

    Great examples Petr, thank you.

    Is it possible to create a procedure that defines a window and it's event-loop, and then call that procedure more than once so you have multiple instances of the same window open, and for each window to handle it's own event-loop correctly?

    There doesn't seem to be any examples that demonstrate the use of multiple windows communicating with each other, would somebody be kind enough to point me in the right direction?

    Thanks again.
    Steve

  7. #7
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    159

    Re: New to interpreter type questions.

    Heres a quick and dirty way.


    [code=thinbasic]
    USES "UI"

    DIM hDlg1, hDlg2 AS DWORD
    DIM ExitFlag AS LONG VALUE = 1
    Dim Msg, wparam,lparam As DWORD

    DIALOG New 0, "APPTITLE1",50,50, 200, 200, _
    %WS_POPUP Or %WS_VISIBLE Or _
    %WS_CLIPCHILDREN Or %WS_CAPTION Or _
    %WS_SYSMENU Or %WS_MINIMIZEBOX, 0 To hDlg1
    DIALOG New 0, "APPTITLE2",150,130, 200, 200, _
    %WS_POPUP Or %WS_VISIBLE Or _
    %WS_CLIPCHILDREN Or %WS_CAPTION Or _
    %WS_SYSMENU Or %WS_MINIMIZEBOX, 0 To hDlg2

    CONTROL ADD BUTTON, hDlg1, 1001, "Click to kill", 10, 50, 150, 10
    CONTROL ADD BUTTON, hDlg2, 2000, "Click to kill", 10, 50, 150, 10

    DIALOG SHOW MODELESS hDlg1
    DIALOG SHOW MODELESS hDlg2

    While ExitFlag ' not equal to 0

    Msg = GETMESSAGE(hDlg1, wParam, lParam)

    Select Case Msg

    Case %WM_Command

    If wParam = 1001 Then ExitFlag = 0 : Exit While

    Case %WM_SYSCOMMAND

    If wParam = %SC_Close Then ExitFlag = 0 : Exit While

    End Select

    Msg = GETMESSAGE(hDlg2, wParam, lParam)

    Select Case Msg

    Case %WM_Command

    If wParam = 2000 Then ExitFlag = 0 : Exit While

    Case %WM_SYSCOMMAND

    If wParam = %SC_Close Then ExitFlag = 0 : Exit While

    End Select

    Wend
    DIALOG END hdlg1
    DIALOG END hDlg2
    [/code]
    Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

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

    Re: New to interpreter type questions.

    @Abraxas, thanks a lot!

    @Steve
    I see you are starting from the simpler one
    To be honest I've never done a script handling more than 1 main window plus some open/close modal dialogs.
    Anyhow, here another way of doing with 3 windows each having its own message pump. One window is considered main window and if it is closed, all will be released. But there can be many other ways of doing things depending on what you need.

    Ciao
    Eros

    [code=thinbasic]
    uses "UI"

    dim hDlg1 as long
    dim hDlg2 as long
    dim hDlg3 as long

    DIM Msg AS LONG
    DIM wParam AS LONG
    DIM lParam AS LONG

    dim RetCode_MainWindow as long

    DIALOG NEW 0, "thinBasic Main Window",-1,-1, 500, 200, _
    %WS_DLGFRAME OR %WS_CAPTION OR %WS_SYSMENU OR %WS_OVERLAPPEDWINDOW, 0 to hDlg1

    CONTROL ADD BUTTON, hDlg1, 10, "Click Me to close all" , 10, 10, 120, 15
    CONTROL ADD BUTTON, hDlg1, 20, "Send message to window 3" , 10, 30, 120, 15

    DIALOG NEW 0, "thinBasic Window 1",-1,-1, 400, 200, _
    %WS_DLGFRAME OR %WS_CAPTION OR %WS_SYSMENU OR %WS_OVERLAPPEDWINDOW, 0 to hDlg2
    CONTROL ADD BUTTON, hDlg2, 10, "Click Me", 10, 10, 60, 15

    DIALOG NEW 0, "thinBasic Window 2",-1,-1, 300, 200, _
    %WS_DLGFRAME OR %WS_CAPTION OR %WS_SYSMENU OR %WS_OVERLAPPEDWINDOW, 0 to hDlg3
    CONTROL ADD BUTTON, hDlg3, 10, "Click Me", 10, 10, 60, 15

    DIALOG SHOW modeless hDlg1
    DIALOG SHOW modeless hDlg2
    DIALOG SHOW modeless hDlg3

    while iswindow(hDlg1)

    RetCode_MainWindow = MessagePump_MainWindow(hdlg1)

    MessagePump_HDLG2(hDlg2)
    MessagePump_HDLG3(hDlg3)

    '---If main window returns %TRUE it means user wants to close dialog
    if RetCode_MainWindow = %TRUE then
    DIALOG END hDlg2
    DIALOG END hDlg3
    exit while
    end if
    WEND

    '---Close the dialog
    DIALOG END hDlg1



    '----------------------------------------------------------------------------
    function MessagePump_MainWindow(hDlg as long)
    '----------------------------------------------------------------------------

    '---Get the message and fill wParam and lParam
    Msg = getMessage(hDlg, wParam, lParam)

    '---Now test the message
    SELECT CASE Msg

    '---Message fired at the very beginning when dialog is initialized
    case %WM_INITDIALOG


    CASE %WM_COMMAND

    '---Test which control has been clicked
    SELECT CASE wParam
    case 10
    Msgbox 0, "Button in main window"
    function = %TRUE
    case 20
    DIALOG SEND hDlg3, %WM_USER + 100, hDlg, 12345678

    end select


    CASE %WM_SYSCOMMAND

    SELECT CASE wParam
    CASE %SC_CLOSE
    function = %TRUE
    END SELECT

    CASE ELSE

    END SELECT


    end function

    '----------------------------------------------------------------------------
    function MessagePump_HDLG2(hDlg as long)
    '----------------------------------------------------------------------------
    DIM Msg AS LONG
    DIM wParam AS LONG
    DIM lParam AS LONG

    Msg = getMessage(hDlg, wParam, lParam)

    select case Msg
    CASE %WM_COMMAND
    SELECT CASE wParam
    case 10
    Msgbox 0, "Button in window 1"

    end select

    end select

    end function

    '----------------------------------------------------------------------------
    function MessagePump_HDLG3(hDlg as long)
    '----------------------------------------------------------------------------
    DIM Msg AS LONG
    DIM wParam AS LONG
    DIM lParam AS LONG

    Msg = getMessage(hDlg, wParam, lParam)

    select case Msg
    CASE %WM_COMMAND
    SELECT CASE wParam
    case 10
    Msgbox 0, "Button in window 2"

    end select

    case %WM_USER + 100
    Msgbox 0, "I'm window 3. I got a message from window " & wParam & " telling me: " & lParam

    end select

    end function

    [/code]

    Script updated:
    • added example on how to send a message from one window to the other

    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

Similar Threads

  1. CH Interpreter
    By zak in forum C / C++
    Replies: 5
    Last Post: 10-03-2012, 09:39
  2. Interactive interpreter
    By Mark0 in forum thinBasic General
    Replies: 7
    Last Post: 28-04-2008, 21:29

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
  •