Results 1 to 1 of 1

Thread: thinBasic Module Maker Script

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    thinBasic Module Maker Script

    Oxygen thinBasic Module Maker Script.

    This is a minimal demo. I had to perform a little workaround for thinBasic_LoadSymbol calls but this seems to be stable.

    I've included some thinCore essentials so you wont need thincore.inc to run this script

    It generates a module called Z (thinBasic_Z.dll)

    Charles

    [code=thinbasic]
    uses "oxygen"

    '---------------------------
    'thinBasic Modules in Oxygen
    '===========================


    dim src as string


    src = "


    ' ####
    ' ########
    ' ## ###
    ' ## ### ####
    ' ## ## ##
    ' ### ### ##
    ' ######## ##
    ' #### ##
    ' ######

    #basic
    #file `thinBasic_z.dll`

    '--------------------------------------
    ' FOR THE FULL FUNCTIONALITY THIS CAN
    ' BE FOUND IN THE THINBASIC SDK FOLDER.
    ' THE PB VERSION IS USED.
    '======================================
    'include `thincore.inc`

    %thinBasic_ReturnNone = 0& 'Used in thinBasic_LoadSymbol to define a sub
    %thinBasic_ReturnNumber = 20& 'Used in thinBasic_LoadSymbol to define a function returning a EXT number
    %thinBasic_ReturnString = 30& 'Used in thinBasic_LoadSymbol to define a function returning a string
    %thinBasic_ReturnCodeByte = 1&
    %thinBasic_ReturnCodeInteger = 2&
    %thinBasic_ReturnCodeWord = 3&
    %thinBasic_ReturnCodeDWord = 4&
    %thinBasic_ReturnCodeLong = 5&
    %thinBasic_ReturnCodeQuad = 6&
    %thinBasic_ReturnCodeSingle = 7&
    %thinBasic_ReturnCodeDouble = 8&
    %thinBasic_ReturnCodeCurrency = 9&
    %thinBasic_ReturnCodeExt = 10&
    %thinBasic_ForceOverWrite = 1& 'Used in thinBasic_LoadSymbol to force symbol over writing

    DECLARE FUNCTION thinBasic_LoadSymbol _
    LIB `thinCore.DLL` _
    ALIAS `thinBasic_LoadSymbol` _
    ( _
    BYVAL SymbolName AS STRING, _
    BYVAL ReturnCode AS LONG, _
    BYVAL FunctionOrSubPointer AS DWORD, _
    OPTIONAL BYVAL ForceOverWrite AS LONG _
    ) AS LONG

    DECLARE SUB thinBasic_ParseNumber LIB `thinCore.DLL` ALIAS `thinBasic_ParseNumber` (Result AS EXT)
    Declare Sub thinBasic_ParseLong Lib `thinCore.DLL` Alias `thinBasic_ParseLong` (Result As Long)
    Declare Function thinBasic_ParseString Lib `thinCore.DLL` Alias `thinBasic_ParseString` (ByRef sResult As String) As Ext
    DECLARE FUNCTION thinBasic_CheckOpenParens_Optional LIB `thinCore.DLL` ALIAS `thinBasic_CheckOpenParens_Optional` () AS LONG
    DECLARE FUNCTION thinBasic_CheckCloseParens_Mandatory LIB `thinCore.DLL` ALIAS `thinBasic_CheckCloseParens_Mandatory` () AS LONG
    DECLARE FUNCTION thinBasic_CheckComma_Optional LIB `thinCore.DLL` ALIAS `thinBasic_CheckComma_Optional` () AS LONG



    '-------------------------------------------------
    function greet alias `greet` () as string external
    '=================================================

    dim As Long ParensPresent
    ParensPresent = thinBasic_CheckOpenParens_Optional
    dim as string s=``
    dim as double d=thinBasic_parseString(s)
    If ParensPresent Then thinBasic_CheckCloseParens_Mandatory

    function=`Hello ` s

    end function

    '--------------------------------------------------
    function cubed alias `cubed` () as ext external
    '==================================================

    dim As Long ParensPresent
    ParensPresent = thinBasic_CheckOpenParens_Optional
    dim as ext e
    thinBasic_parseNumber(e)
    If ParensPresent Then thinBasic_CheckCloseParens_Mandatory
    function=e^3
    end function

    '--------------------
    sub finish() external
    '====================
    'print `finish`
    terminate
    end sub


    '----------------------------------------------------------------------------------------------
    function LoadLocalSymbols Cdecl ALIAS `LoadLocalSymbols` (BYVAL sPath AS STRING) AS Long export
    '==============================================================================================

    '------------------
    'pseudo ole bstring
    'and low level call
    '==================

    dim as zstring z(32)
    dim f=?thinBasic_LoadSymbol
    dim a

    '-------------
    def LoadSymbol
    '=============
    z(5)=`%1` : a=&z+4 : ?z=20
    proc f a , thinBasic_%2 , &%1 , thinBasic_ForceOverWrite
    end def

    LoadSymbol greet ReturnString
    LoadSymbol cubed ReturnNumber

    end function

    '--------------------------------------------------------------------------------------------------
    function UnLoadLocalSymbols Cdecl ALIAS `UnLoadLocalSymbols` (BYVAL sPath AS STRING) AS Long export
    '==================================================================================================
    end function



    "

    ' ##### ###### ###### ###### ###
    ' ######## ######### ######### ######### #####
    ' ## ## ## ## ## ## ## ## ##
    ' ## ## ## ## ## ## ## ## ##
    ' ## ## ## ## ## ## ## ## ##
    ' ## ## ## ## ## ## ## ## ##
    ' ## ## ## ## ## ## ## ## ##
    ' ## ########## ########## ########## ##########
    ' # ###### ###### ###### ######
    '
    '

    'msgbox 0,o2_prep src
    o2_asmo src


    if len(o2_error) then
    msgbox 0, "ERROR:"+$cr+o2_error()
    else
    msgbox 0,"COMPILED OK"
    end if


    [/code]


    Test Script:
    [code=thinbasic]

    '---------------------------
    'thinBasic Modules in Oxygen
    '===========================

    'MODULE TESTING SCRIPT

    uses "z"
    msgbox 0,greet "World"
    msgbox 0,cubed 3
    [/code]
    Attached Files Attached Files

Similar Threads

  1. module maker test :)
    By Lionheart008 in forum O2h Compiler
    Replies: 5
    Last Post: 26-05-2010, 08:57

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
  •