SpiderBasic 3.30 beta 1 is out !

Everything else that doesn't fall into one of the other categories.
Fred
Site Admin
Posts: 1873
Joined: Mon Feb 24, 2014 10:51 am

SpiderBasic 3.30 beta 1 is out !

Post by Fred »

Hi folks,

Here is the new 3.30 beta version of SpiderBasic introducing a nice new feature we wanted to implement since a while: async/await support. What does it means for you ? Less callbacks ! The commands can finally wait for there execution to finish and you can code in a more linear fashion.

For example, using the OpenFileRequester() to display a local image was looking like that:

Code: Select all

Procedure Loaded(Type, Filename$, ObjectId)
  Static x = 200, y = 200
  
  OpenWindow(#PB_Any, x, y, 300, 300, Filename$, #PB_Window_TitleBar | #PB_Window_SizeGadget)
    ImageGadget(#PB_Any, 0, 0, ImageWidth(ObjectId), ImageHeight(ObjectId), ImageID(ObjectId))
    
  ; Shift the next opened window
  ;
  x + 40 
  y + 40
EndProcedure


Procedure LoadingError(Type, Filename$)
  Debug Filename$ + ": loading error"
EndProcedure

 
Procedure RequesterSuccess()
  
  ; Process all the selected filename
  ;
  While NextSelectedFile()
    LoadImage(#PB_Any, SelectedFileID(), #PB_LocalFile) ; when using #PB_LocalFile, all files selected with OpenFileRequester() are directly available
    Filename$ = SelectedFileName()
  Wend
  
EndProcedure

Procedure ButtonEvent()
  OpenFileRequester("image/*", @RequesterSuccess(), #PB_Requester_MultiSelection)
EndProcedure


OpenWindow(0, 100, 100, 200, 45, "Image viewer", #PB_Window_TitleBar)
ButtonGadget(0, 10, 10, 180, 25, "Open local image...")
BindGadgetEvent(0, @ButtonEvent())

; Register the loading event before calling any resource load command
BindEvent(#PB_Event_Loading, @Loaded())
BindEvent(#PB_Event_LoadingError, @LoadingError())
Now, the same code using async under the loop makes the code easier to follow and more PureBasic-like

Code: Select all

Procedure ButtonEvent()
  x = 200
  y = 200
  
  Filename$ = OpenFileRequester("image/*", #PB_Requester_MultiSelection)
  
  ; Process all the selected filename
  ;
  While Filename$
    Image = LoadImage(#PB_Any, Filename$, #PB_LocalFile) ; when using #PB_LocalFile, all files selected with OpenFileRequester() are directly available
    If Image
        
      OpenWindow(#PB_Any, x, y, 300, 300, Filename$, #PB_Window_TitleBar | #PB_Window_SizeGadget)
        ImageGadget(#PB_Any, 0, 0, ImageWidth(Image), ImageHeight(Image), ImageID(Image))
    
      ; Shift the next opened window
      ;
      x + 40 
      y + 40
    EndIf
    
    Filename$ = NextSelectedFilename()
  Wend
EndProcedure

OpenWindow(0, 100, 100, 200, 45, "Image viewer", #PB_Window_TitleBar)
ButtonGadget(0, 10, 10, 180, 25, "Open local images...")
BindGadgetEvent(0, @ButtonEvent())
This is early work on this and if it works well it be done for the whole commandset. I tested on cordova and it works as expected, but feel free to test and see if it is OK.

The modified affected commands which now uses await:

Code: Select all

CaptureImage()
CloseFile()
CopyFile()
CreateDirectory()
DeleteDirectory()
DeleteFile()
ExamineDirectory()
FetchData()
FileSize()
GetFileAttributes()
GetFileDate()
HTTPRequest()
LoadImage()
LoadJSON()
LoadScript()
LoadSound()
LoadSprite()
LoadXML()
OpenFileRequester()
ReadFile()
RequestFileSystem()
SetCurrentDirectory()
That means that these commands doesn't need a callback anymore and will returns the result directly when the processing is done, actually blocking the program flow.

Here is the change list for this version:

Code: Select all

  - Added: async/await support for most of the commands, callbacks are now optionals and program flow easier to follow !
  - Added: FileSystem library to easily act on local files (iOS, Android only)
  - Added: Preference library using local storage based on Peter's work (Thanks ! https://github.com/spiderbytes/Preferences)
  - Added: CaptureImage() to get an image from the camera (iOS, Android only)
  - Added: CreatePasswordHash() and VerifyPasswordHash() based on bcrypt
  
  - Optimized: Splitted the system library to not have all cordova libs included when using a single command
  - Optimized: Android app creation should be much faster on Windows
  
  - Changed: NextSelectedFile() to NextSelectedFileName()
  - Removed SelectedFileName() and SelectedFileID()
Have fun !

The Fantaisie Software team
hoerbie
Posts: 146
Joined: Sun Mar 17, 2019 5:51 pm
Location: DE/BY/MUC

Re: SpiderBasic 3.30 beta 1 is out !

Post by hoerbie »

Hi @Fred,
is there any general download problem for the new beta?
Because I can't find any beta downloads when logging in, although my license is paid until october 26?
Greets, hoerbie
Post Reply