PB2Web -- A PureBasic to JavaScript-Converter

Developed or developing a new product in PureBasic? Tell the world about it.
User avatar
Kiffi
Addict
Addict
Posts: 1484
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: PB2Web -- A PureBasic to JavaScript-Converter

Post by Kiffi »

sorry, my fault

this one is correct (you have to use callbacks):

Code: Select all

Procedure GetData_Success(ReceivedData.s)
  MessageRequester("Success", ReceivedData)
  SetGadgetText(#fmuser, "")
  SetGadgetText(#fmlocation, "")  
EndProcedure

Procedure GetData_Error(a.s, b.s, c.s)
  MessageRequester("Error", b + " / " + c)
EndProcedure

Procedure DataRecord()  
  Protected user.s
  Protected location.s
 
  user = GetGadgetText(#fmuser)
  location = GetGadgetText(#fmlocation)
  
  P2W_Converter_Begin_Raw
  ;$.ajax({
  ;   type: "GET",
  ;   url: 'test.php',
  ;   data: { action: "post", user: user, location: location },
  ;
  ;   success : function(data) {
  ;       GetData_Success(data);
  ;    },
  ;
  ;   error : function(a, b, c) {
  ;       GetData_Error(a, b, c);
  ;    }
  ;
  ;});
  P2W_Converter_End_Raw
  
EndProcedure
Greetings ... Kiffi
Hygge
User avatar
falsam
Enthusiast
Enthusiast
Posts: 632
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: PB2Web -- A PureBasic to JavaScript-Converter

Post by falsam »

Excellent Kiffi!! I did not realize it was possible to call a procedure PureBasic from ajax code. That's great :)

➽ Windows 11 64-bit - PB 6.21 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect 🤪
Poshu
Enthusiast
Enthusiast
Posts: 459
Joined: Tue Jan 25, 2005 7:01 pm
Location: Canada

Re: PB2Web -- A PureBasic to JavaScript-Converter

Post by Poshu »

I was wondering : can we take part in the development of PB2Web?
User avatar
Kiffi
Addict
Addict
Posts: 1484
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: PB2Web -- A PureBasic to JavaScript-Converter

Post by Kiffi »

@falsam:

same solution with ServerCode (CGI). No need to code in ugly PHP ;-)

Code: Select all

ProcedureDLL.s WriteUserAndLocation(User.s, Location.s)
  
  Protected FF
  
  FF = OpenFile(#PB_Any, "test.txt", #PB_File_Append)
  
  If FF
    WriteStringN(FF, User + "|" + Location)
    CloseFile(FF)
    ProcedureReturn "OK"
  Else
    ProcedureReturn "!OpenFile()"
  EndIf
  
EndProcedure

Procedure DataRecord()
  
  Protected user.s
  Protected location.s
  Protected ReturnValue.s
  
  user = GetGadgetText(#fmuser)
  location = GetGadgetText(#fmlocation)
  
  ReturnValue = WriteUserAndLocation(user, location)
  
  If Left(ReturnValue, 2) = "OK" ; ReturnValue contains linebreak
    SetGadgetText(#fmuser, "")
    SetGadgetText(#fmlocation, "")  
    MessageRequester("Information", "Updated.")
  Else
    MessageRequester("Information", "Something went wrong")
  EndIf
  
EndProcedure
@Poshu: Thanks for the offer! I will think about it.

Greetings ... Kiffi
Hygge
User avatar
[blendman]
Enthusiast
Enthusiast
Posts: 297
Joined: Thu Apr 07, 2011 1:14 pm
Location: 3 arks
Contact:

Re: PB2Web -- A PureBasic to JavaScript-Converter

Post by [blendman] »

Hi

1) Some informations on PB2Web (for Kiffi ;)) :

In a procedure, this code doesn't work (same with - * / ):

Code: Select all

x + 1
We have to use :

Code: Select all

x = x + 1

This code doesn't work (in a procedure) :

Code: Select all

Select x  
  
  Case 0    

    Select y   
     
      Case 0
        ; ...
      Case 1
        ; ...
    EndSelect 
    
  Case 1
    
    Select y
        
      Case 0
        ; ...
      Case 1
        ; ...
    EndSelect
    
EndSelect
We have to use :

Code: Select all

If x  = 0    

    Select y   
     
      Case 0
        ; ...
      Case 1
        ; ...
    EndSelect 
    
ElseIf x  = 1  
    
    Select y
        
      Case 0
        ; ...
      Case 1
        ; ...
    EndSelect
    
Endif
Not implemented for the moment ?
- EventMenu() : It send "undefined" as returned value ;) (It's not finished, I suppose ;)).
- ButtonImageGadget() : we can create the button, but for the moment, the bind event isn't implemented, it's exact ?
- Drawtext() : not implemented ? We have a debug message : "alpha isn't implemented" (I like Alpha : RGBA(), DrawAlphaImage()... :))


2) A new version of my Paint test program :
http://www.dracaena-studio.com/purebasic/paint/

New :
- we can use image to draw (some brush are from the SlotMachine demo, thanks ;))
- Tool : eraser, clear, brush
- panel Layers/options (Only UI)

Source (zip):
http://www.dracaena-studio.com/purebasi ... int0.1.zip
User avatar
Kiffi
Addict
Addict
Posts: 1484
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: PB2Web -- A PureBasic to JavaScript-Converter

Post by Kiffi »

[blendman] wrote:In a procedure, this code doesn't work (same with - * / ):

Code: Select all

x + 1
annotation: x + 1 works but x\something + 1 doesn't work. ;-) I'am on it.
[blendman] wrote:Select [...]
mmmh. This one works:

Code: Select all

Define x = 1
Define y = 0

Select x
  Case 0    
    Select y   
      Case 0
        Debug "x=0 y=0"
      Case 1
        Debug "x=0 y=1"
    EndSelect 
  Case 1
    Select y
      Case 0
        Debug "x=1 y=0"
      Case 1
        Debug "x=1 y=1"
    EndSelect
EndSelect
can you provide a simple snippet to reproduce the error?
[blendman] wrote: - EventMenu() : It send "undefined" as returned value ;) (It's not finished, I suppose ;)).
- ButtonImageGadget() : we can create the button, but for the moment, the bind event isn't implemented, it's exact ?
implementet, but not published. Stay tuned.
[blendman] wrote: - Drawtext() : not implemented ? We have a debug message : "alpha isn't implemented" (I like Alpha : RGBA(), DrawAlphaImage()... :))
yes, unfortunately the most of the 2DDrawing-Library functions aren't implemented.

Greetings ... Kiffi
Hygge
User avatar
falsam
Enthusiast
Enthusiast
Posts: 632
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: PB2Web -- A PureBasic to JavaScript-Converter

Post by falsam »

Kiffi wrote:can you provide a simple snippet to reproduce the error?

Code: Select all

XIncludeFile "D:\Applications\Pure Basic\Pb2Web\p2w.pbi"

P2W_Converter_SetProfile("pb2webtest")

Procedure dummy(x)  
  Select x
    Case 1,3
      Debug "Value is 1 or 3"
      
    Case 10 To 20
      Debug "this value is between 10 and 20"
      
    Default
      Debug "Hmmm ...I don't know"
      
  EndSelect
EndProcedure

dummy(10)
A problem with "To"

➽ Windows 11 64-bit - PB 6.21 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect 🤪
User avatar
[blendman]
Enthusiast
Enthusiast
Posts: 297
Joined: Thu Apr 07, 2011 1:14 pm
Location: 3 arks
Contact:

Re: PB2Web -- A PureBasic to JavaScript-Converter

Post by [blendman] »

Kiffi wrote:annotation: x + 1 works but x\something + 1 doesn't work. ;-) I'am on it.
ok, great !
[blendman] wrote:Select [...]
mmmh. This one works
Yes, it work. Sorry, I have the version 2014/01/14 and not the 2014/01/15 of PB2Web ;).

[blendman] wrote: - EventMenu() : It send "undefined" as returned value ;) (It's not finished, I suppose ;)).
- ButtonImageGadget() : we can create the button, but for the moment, the bind event isn't implemented, it's exact ?
implemented, but not published. Stay tuned.
It's a great news ! I'm waiting (PB2Web is magic ;)).
User avatar
falsam
Enthusiast
Enthusiast
Posts: 632
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: PB2Web -- A PureBasic to JavaScript-Converter

Post by falsam »

Kiffi wrote:No need to code in ugly PHP ;-)
Yes my code PHP is ugly :mrgreen:

Thanks for your reply but i can't register data.

■ My code (with your help)

Code: Select all

XIncludeFile "D:\Applications\Pure Basic\Pb2Web\p2w.pbi"

P2W_Converter_SetProfile("pb2webtest")

Enumeration
  #mainform
  #fmuserslist
  #fmuser
  #fmlocation
  #fmuserupdate
EndEnumeration

ProcedureDLL.s WriteUserAndLocation(User.s, Location.s)
  
  Protected FF
  
  FF = OpenFile(#PB_Any, "users.txt", #PB_File_Append)
  
  If FF
    WriteStringN(FF, User + "|" + Location)
    CloseFile(FF)
    ProcedureReturn "OK"
  Else
    ProcedureReturn "!OpenFile()"
  EndIf
  
EndProcedure

Procedure DataRecord()
  
  Protected user.s
  Protected location.s
  Protected ReturnValue.s
  
  user = GetGadgetText(#fmuser)
  location = GetGadgetText(#fmlocation)
  
  If Trim(user) = ""
    MessageRequester("Information", "The username you entered is too short.") 
  Else
    ReturnValue = WriteUserAndLocation(user, location)
  
    Debug "WriteUserAndLocation say " +ReturnValue
  
    If Left(ReturnValue, 2) = "OK" ; ReturnValue contains linebreak
      SetGadgetText(#fmuser, "")
      SetGadgetText(#fmlocation, "") 
      MessageRequester("Information", "Updated.")
      AddGadgetItem(#fmuserslist, -1, user+Chr(10)+location) 
    Else
     MessageRequester("Information", "Something went wrong")
    EndIf
  EndIf
  
EndProcedure

Procedure WindowShow()
  OpenWindow(#mainform, 0, 0, 450, 450, "Demo : Test open and write file", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
  SetWindowColor(#mainform, RGB(255, 239, 213))
  ListIconGadget(#fmuserslist, 20, 40, 400, 300, "User", 200)
  AddGadgetColumn(#fmuserslist, 1, "Location", 200)
  
  TextGadget(#PB_Any, 20, 350, 80, 25, "User")
  StringGadget(#fmuser, 100, 350, 200, 22, "")
  
  TextGadget(#PB_Any, 20, 390, 80, 25, "Location")
  StringGadget(#fmlocation, 100, 390, 200, 22, "")
  
  ButtonGadget(#fmuserupdate, 310, 350, 80, 22, "Update")
  
  TextGadget(#PB_Any, 20, 430, 400, 22, "Proudly Powered by <b>Pure Basic</b> & <b>PB2Web</b>") 
  
  BindGadgetEvent(#fmuserupdate, @DataRecord())
    
EndProcedure

WindowShow()

P2W_Converter_Begin_Comment
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
P2W_Converter_End_Comment
■ Profile Manager setting.
Image

■ Result when I am trying to validate a user.
Image

■ Test Zone (Profile Manager is update)
Server 1and1 (linux)
Last edited by falsam on Sat Jan 18, 2014 1:42 am, edited 1 time in total.

➽ Windows 11 64-bit - PB 6.21 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect 🤪
User avatar
Kiffi
Addict
Addict
Posts: 1484
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: PB2Web -- A PureBasic to JavaScript-Converter

Post by Kiffi »

@falsam: Thanks for the snippet. I will check it.
falsam wrote:Server 1and1 (linux)
ok, that's the reason. PB2Web compiles the ServerCode to an
Windows-Executable, so you cannot use it on a Linux-Server.

Therefore unfortunately you must to continue to code in PHP.

Greetings ... Kiffi

// Edit: oh, sorry, i see that you are using WAMPP. So your Apache
is configured, that he sends you the EXE instead of executing it.
Hygge
User avatar
venom27
User
User
Posts: 10
Joined: Mon Sep 14, 2009 5:30 pm
Location: . <------ ici
Contact:

Re: PB2Web -- A PureBasic to JavaScript-Converter

Post by venom27 »

Bravo, excellent work.
Good luck...







@++
Windows 10 x64, PureBasic 5.71 Beta 1 x86 & x64
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: PB2Web -- A PureBasic to JavaScript-Converter

Post by Tenaja »

Kiffi wrote:PB2Web compiles the ServerCode to an Windows-Executable, so you cannot use it on a Linux-Server.
Others have done essentially the same thing, and posted it here on the forum, sharing source that works with both Windows and Linux servers.
http://purebasic.fr/english/viewtopic.p ... 1&p=379023
http://www.purebasic.fr/english/viewtopic.php?p=133389
http://www.purebasic.fr/english/viewtop ... 14&t=37397
User avatar
falsam
Enthusiast
Enthusiast
Posts: 632
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: PB2Web -- A PureBasic to JavaScript-Converter

Post by falsam »

Kiffi wrote:Therefore unfortunately you must to continue to code in PHP.
code in ugly PHP :wink:

➽ Windows 11 64-bit - PB 6.21 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect 🤪
User avatar
Kiffi
Addict
Addict
Posts: 1484
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: PB2Web -- A PureBasic to JavaScript-Converter

Post by Kiffi »

Tenaja wrote:Others have done essentially the same thing
PB2Web compiles this [1] code from Deluxe0321 (modified a little bit by me)
on the fly (during parsing the code). The source can be found under
'[...]\pb2web\system\CGI\' but nevertheless the executable-format
depends on the underlying OS.

[1]: http://www.purebasic.fr/english/viewtop ... 12&t=35321

Greetings ... Kiffi
Hygge
User avatar
falsam
Enthusiast
Enthusiast
Posts: 632
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: PB2Web -- A PureBasic to JavaScript-Converter

Post by falsam »

Angry with the cgi, I changed my test code. I communicate with a php script that allows you to add and list data in a text file.

Demo and download by clicking this link:

:arrow: Click this link to launch the demo and download the source. : PB2Web : Demo PHP

Do not hesitate to enter your nickname and location.

Note: This is only a demonstration. Php code is not secure and ugly :wink: .

➽ Windows 11 64-bit - PB 6.21 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect 🤪
Locked