IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

Vous êtes nouveau sur Developpez.com ? Créez votre compte ou connectez-vous afin de pouvoir participer !

Vous devez avoir un compte Developpez.com et être connecté pour pouvoir participer aux discussions.

Vous n'avez pas encore de compte Developpez.com ? Créez-en un en quelques instants, c'est entièrement gratuit !

Si vous disposez déjà d'un compte et qu'il est bien activé, connectez-vous à l'aide du formulaire ci-dessous.

Identifiez-vous
Identifiant
Mot de passe
Mot de passe oublié ?
Créer un compte

L'inscription est gratuite et ne vous prendra que quelques instants !

Je m'inscris !

SpiderBasic 3.30 beta 1 est disponible sur votre compte

Le , par comtois

5PARTAGES

4  0 
Je ne traduis pas, votre anglais est meilleur que le mien.

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 : Sélectionner tout
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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 : Sélectionner tout
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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:

  • 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:

  • 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
Source de l'information
Vous avez lu gratuitement 18 580 articles depuis plus d'un an.
Soutenez le club developpez.com en souscrivant un abonnement pour que nous puissions continuer à vous proposer des publications.

Une erreur dans cette actualité ? Signalez-nous-la !