Announcement

Collapse
No announcement yet.

What is hapening with PluriBASIC?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • What is hapening with PluriBASIC?


    Probably too much for a single developer. But I will try to continue. Here are some tips for PHP:

    Php scripts have a ton of new features. Probably more than i can document in a short time, like when making a forum post.

    There are now CLIENT FUNCTIONS, which get converted to Javascript and embedded in the output of FORMOUT().
    This means it converts regular functions to PHP and also converts CLIENT functions to Javascript in the same step.

    This, of course has some implications, some of the features intended for PHP would be generated also for javascript, but
    we have something for it too. Suppose you want to have a small portion of HTML code that you want to include in a javascript,
    but it is never used in the PHP part of the generated code, then you can do this:

    Code:
    #FORM CLIENT SomeCode, "somecode.html"
    Of some code that you will use in the PHP portion of code but it is not used in Javascript:

    Code:
    #FORM SERVER SomeCode, "somecode.html"
    Or... if you will use it in both client and server (or if you dont have CLIENT functions), simply:

    Code:
    #FORM SomeCode, "somecode.html"
    Many of the same PluriBASIC features used in PHP can be used in the Javascript portion of it with the same syntax. For example, FORMFIELD in PHP
    would contain the fields of a submitted form, while for the JavaScript would contain the fields of a form that has not been submitted yet.

    There will be some cases in which you will want to use direct Javascript, so, RAW sections can be used in those cases, it is very simple to do so, for
    example, you can embed an mp3 sound file for your Javascript generated code like this:

    Code:
    #FILE CLIENT Ding,          "ding.mp3"
    And include a CLIENT function like this:

    Code:
    CLIENT FUNCTION Play(BYREF s AS STRING) AS LONG
          BEGIN RAW
               try {
                        s[0].currentTime = 0;
                        s[0].play();
                    }   catch (error) {
                        var b64 = btoa(s[0]);
                        s[0] = document.createElement("audio");
                        s[0].src = "data:audio/mp3;base64," + b64;
                        s[0].type = "audio/mpeg";
                        s[0].play();
                    }
           END RAW
     END FUNCTION
    Then you would be a ble to play the sound using this PluriBASIC syntax:

    Code:
    Ding.Play
    Or...
    Code:
    Play(Ding)
    Note that modern browsers wont play any sounds or videos unless a user interaction has been performed in the page first,
    like a mouseclick or a keypress. This is only a function example, every file embedded file bloats the javascript code. Loading an external
    file would be more eficcient.



    Ill try to keep posting more undocumented tips.
    Last edited by Brian Alvarez; 20 Jun 2021, 09:28 PM.
    www.pluribasic.com
    www.patreon.com/pluribasic

  • #2
    When the modules are compiled with the directive:

    #DIM ALL

    ... All the normal variables must be declared before being used, however, there is a special type of
    disposable universal variable that requires no declaration.

    Code:
    $.variable = "Hello World"
    These variables do not require a declaration of data type, because those can hold strings or numbers,
    of even change what they are holding on the fly. These can be used in a variety of situations.

    These variables are very flexible, for example, you can store a string of text representing a
    number, then use any feature that alters numbers, and then get the string back. Like this:

    Code:
    $.number = "12345"
    
    INCR $.number BY 10
    
    STDOUT $.number & " as a string."
    PluriBASIC detects what the code is expecting from the variable and automatically uses the
    numeric or string form of it.

    These special variables are tacitly GLOBAL, and its main purpose is for use with PROCSTR()
    for embedding it's contents in a web form. This is done by adding it to a portion of HTML code,
    for example:

    Code:
    $.video = VideoCode
    
    STDOUT PROCSTR("<div id='videoarea' style='float: left;'>[$.video]</div>")
    These special variables do not collide with other variables. In the above example, you could have
    a global, local or any other scope of variable named video.

    www.pluribasic.com
    www.patreon.com/pluribasic

    Comment


    • #3
      Having a Dynamic string member in an user-defined data type variable is often useful. Well, now you can have them
      with PluriBASIC. For example:

      Code:
      TYPE UserData  ALIAS "MySQL_TableName"
               ID           CONDITION AUTOINC NOTNULL PRIMARY AS LONG
               name         AS STRING * 32
               eMail        AS STRING * 64
               Password     AS STRING * 16
               Notes        AS STRING
      END TYPE
      
      FUNCTION PBMAIN() AS LONG
           LOCAL Usr AS UserData
      
           Usr.Notes = "This string can be of any length, as long as the system allows it, it can be like any other dynamic string."
      
      END FUNCTION
      This is supported for all target platforms, including PowerBASIC. PluriBASIC handles all the allocation and deallocation of the dynamic strings.

      It has some limitations though, using UDT's that have dynamic strings in them cannot be loaded from or saved directly to file using PUT and GET.
      Also, for the moment you cannot have arrays of UDT's that contain dynamic strings (members with dimensions are supported though). Maybe in the future, this will be implemented.

      You can, however use all the PluriBASIC features with them, like PROCSTR functionality, DATABASE features, UDT features, RESET... Etc. are also compatible.
      You can also pass them BYVAL or BYREF normally, PluriBASIC handles it. For example, the following code is compatible with UDTS that have dynamic strings:

      Code:
      IF DATABASE.load(Usr, "where id=2") THEN
         ' Do something with the data loaded to the UDT.
      END IF
      or...
      Code:
      LOCAL Jstr AS STRING = UDT.json(Udt)
      
      STDOUT Jstr;
      All these features have proven to be very useful for WEB development.







      www.pluribasic.com
      www.patreon.com/pluribasic

      Comment


      • #4
        When you are building rows of a table, or repetitive code that needs to have a small detail
        different for each element, you dont have to handle the settings manually for each element
        or concatenate strings manually.

        You can specify each row's details with HTML.row().

        For example suppose you need to build a several DIV's in succession, but you want each div
        to alternate colors, and have different data in them... you can add several strings as follows:

        Code:
        HTML.Row("backgroundcolor", "#f5f5f5", "#e5e5e5")
        This will specify color #f5f5f5 as the first color, and #e5e5e5 as the second color. You can add more
        colors if you need to.

        You can embed the DIV code as a meta-statement as follows:

        Code:
        #FORM SomeRow, "SomeRow.html"
        The File SomeRow.html contains this:

        Code:
        <div style="background-color: [$backgroundcolor]; color: [$fontcolor];">[!usr.name]</div>
        Then you can specify a FOR/LOOP block like this:

        Code:
        For R = 1 TO 4
           ' Add a processed row
           $.allrows &= PROCSTR(SomeRow) & $CRLF
        
           ' Manually jump to the next setting.
           Html.next
        NEXT R
        ' Output all the generated rows.
        CALL FORMOUT($.allrows)
        You can specify up to 31 settings. Settings do not need to be in pairs, each setting loops according to
        the number of settings in each keyword. For example, suppose you have 2 alternate backgroundcolor's, and 3 fontcolor's, as follows:

        Code:
        HTML.Row("backgroundcolor", "#f5f5f5", "#e5e5e5")
        HTML.Row("fontcolor", "#ffffff", "#c0c0c0", "blue")
        In that case:

        Code:
        DIV 1 would be backgroundcolor #f5f5f5 and fontcolor, #ffffff.
        DIV 2 would be backgroundcolor #e5e5e5 and fontcolor, #c0c0c0.
        DIV 3 would be backgroundcolor #f5f5f5 and fontcolor, blue.
        DIV 4 would be backgroundcolor #e5e5e5 and fontcolor, #ffffff.
        In order to jump to the next setting you can use:

        Code:
        Html.next
        Or...
        Code:
        DATABASE.next(SomeUDT)
        Or if you are within a FOR EACH block that loads data from a database, you can simply use:

        Code:
        NEXT SomeUDT
        Like this:

        Code:
        FOR EACH Usr WHERE "id > 30"
           ' Add a processed row
           $.allrows &= PROCSTR(SomeRow) & $CRLF
        
           ' Next setting is automatically used on the next iteration in this type of FOR blocks.
        NEXT Usr
        Last edited by Brian Alvarez; 24 Jun 2021, 06:32 PM.
        www.pluribasic.com
        www.patreon.com/pluribasic

        Comment


        • #5
          Code:
          #OPTIONS HTTPS
          Will force scripts to be executed in HTTPS mode. This also works for PBWIN CGI scripts.
          www.pluribasic.com
          www.patreon.com/pluribasic

          Comment

          Working...
          X