IDE for CX

bosh77

New member
Joined
Oct 26, 2019
Messages
26
Hi, I'm trying to create an IDE for CX written with CX itself, then available for all desktop versions.
I added the window on the left that contains variables, functions, etc ...
I think I also add Intellisense and other functions.

I would have two problems:
1 - How can I "capture" the text that appears in the console at the time of compilation and execution of the .CXS files?
2 - Is it possible to exclude the Openal library when compilation, so as not to have to distribute the openal32.dll file?


screenshot2.png
 

MikeHart

Administrator
3rd Party Module Dev
3rd Party Target Dev
3rd Party Tool Dev
Joined
Jun 19, 2017
Messages
3,346
Regarding the openal files, it should be fine to leave them out.

Regarding getting STDOUT and STDERR, imho there is no module that ships with CX that does that atm.
Will have a look if I can find one online.
 

Phil7

Administrator
CX Code Contributor
3rd Party Tool Dev
Joined
Jun 26, 2017
Messages
698
You can look into the process module. I didn't try it but maybe you can use the Process class there and run transcc as a subprocess with STDOUT
 
Last edited:

dawlane

Well-known member
CX Code Contributor
Tutorial Author
Joined
Jun 21, 2017
Messages
937
Regarding the openal files, it should be fine to leave them out.
If this application is base on any target that needs any Mojo module, then openal is a requirement due to how the main native sources are written and how CX generates native sources. It's why CServer needs it even though it doesn't use it.

You can look into the pocess module. I didn't try it but maybe you can use the Process class there and run transcc as a subprocess with STDOUT
Yeah it should be possible to use, or extend the Process class. Though the documentation states that Process.Start returns void, even though the description returns a boolean if the a process was successfully started.
 

bosh77

New member
Joined
Oct 26, 2019
Messages
26
I am trying to exclude Openal but I don't know how to do it.

Regarding STDOUT I had managed with Visual Basic.net to get the flow of text in real time during the Runtime but in C++ I don't know how to do it, sorry for my ignorance but I don't know the language well.
With VB.NET I used CommandExecutor and an event that occurred every time there was new text to view.
 

Phil7

Administrator
CX Code Contributor
3rd Party Tool Dev
Joined
Jun 26, 2017
Messages
698
get the flow of text in real time during the Runtime but in C++ I don't know how to do it
You don't need C++ for that. It is a Cerberus module I was talking about. The simplest way to get the output of a process is this.
Code:
Strict

Import brl.process

Function Main:Int()
    Local stdOutString:String
    stdOutString = Process.Execute("help")
    Print "StdOut: " + stdOutString
    Return 0
End
 

bosh77

New member
Joined
Oct 26, 2019
Messages
26
ok but I only get it when the application is finished.
I would like to get the flow of text like when I compile and run a CX app.
 

Phil7

Administrator
CX Code Contributor
3rd Party Tool Dev
Joined
Jun 26, 2017
Messages
698
For that I would try to start the process with Process.Start() and then check in OnUpdate() with StdoutAvail if there is something to read using ReadStdout().

Docs might help ;-)
 

bosh77

New member
Joined
Oct 26, 2019
Messages
26
I tried Process.Start() but I get Memory access violation

Cerberus Runtime Error : Memory access violation
D:/appdesktop/CXIDE/cxide.cxs<23>
C:/Cerberus_v2021-07-25/modules/mojo/app.cxs<96>
 

dawlane

Well-known member
CX Code Contributor
Tutorial Author
Joined
Jun 21, 2017
Messages
937
You have to create an object using:
Local process:=New Process()
process.Start("the_full_path_of_the_app")

You then have to check if the process is still running, then query the standard streams.
 

dawlane

Well-known member
CX Code Contributor
Tutorial Author
Joined
Jun 21, 2017
Messages
937
Here's a working example.
Cerberus:
Strict

Import brl.process
Import brl.databuffer

Enumerate
    ERROR_OK=0,
    ERROR_FAIL=-1,
    ERROR_TERMINATE=-2
 
Function Main:Int()
    Local err:=Run("C:\cerberus\bin\transcc_winnt.exe -target=Desktop_Game -config=release -run C:\cerberus\examples\mojo\charlie\blobmonster\blobmonster.cxs")

    Select err
        Case ERROR_OK
            Print "Successfully executed: "+err
        Case ERROR_FAIL
            Print "Failed to execute: "+err
        Case ERROR_TERMINATE
            Print "Terminated execution: "+err
        Default
            Print "Unknown exit condition: "+err
    End Select
 
    Return 0
End

Function Run:Int(cmd:String)
    If cmd = "" Return ERROR_FAIL
 
    Local process:= New Process(), buffer:DataBuffer=Null
 
    Print "~nExecuting: ~n"+cmd
    If Not process.Start(cmd) Return ERROR_FAIL
 
    Local bytesRead:=0, bytesAvail:=0
    While process.IsRunning()
        ' At this point, check if the user has terminate the process manually.
        ' You should call process.Kill(ERROR_TERMINATE) and return from the function will ERROR_TERMINATE as the value.

        Try
            If buffer buffer.Discard()
            If process.StderrAvail()>0 Throw New Throwable()
    
            bytesAvail = process.StdoutAvail()
            If bytesAvail>0
                buffer = New DataBuffer(bytesAvail)
                bytesRead = process.ReadStdout(buffer, 0, bytesAvail)
                If bytesRead>0 Print buffer.PeekString(0).Trim()
            Endif
        
        Catch e:Throwable
            bytesRead = 0
            bytesAvail = process.StderrAvail()
            If bytesAvail>0
                buffer = New DataBuffer(bytesAvail)
                bytesRead = process.ReadStderr(buffer, 0, bytesAvail)
            Endif
            If bytesRead>0 Print "ERROR: "+ buffer.PeekString(0).Trim() Else Print "ERROR UNKNOWN"
            Exit
        End
    Wend

    Return process.Wait()

End
 
Last edited:

bosh77

New member
Joined
Oct 26, 2019
Messages
26
Really thank you very much, just what I needed
Thanks also to Phil7
 

dawlane

Well-known member
CX Code Contributor
Tutorial Author
Joined
Jun 21, 2017
Messages
937
Note that the working example hasn't been test with StderrAvail being thrown. So the exit code could end up being wrong.
 
Last edited:

Wingnut

Well-known member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
1,196
Is this possible on mac to?
 

Phil7

Administrator
CX Code Contributor
3rd Party Tool Dev
Joined
Jun 26, 2017
Messages
698
Yes, this should work on all desktop targets (glfw and stdcpp).
 

Wingnut

Well-known member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
1,196
Well i get this.

Of course there is a linw that contains window specifica code. I suspect it needs to be changed.

Code:
TRANS cerberus compiler V2021-12-27
Parsing...
Semanting...
Translating...
Building...
main.cpp:1527:5: warning: 'TARGET_OS_IPHONE' is not defined, evaluates to 0 [-Wundef-prefix=TARGET_OS_]
#if TARGET_OS_IPHONE
    ^
main.cpp:1588:5: warning: 'TARGET_OS_IPHONE' is not defined, evaluates to 0 [-Wundef-prefix=TARGET_OS_]
#if TARGET_OS_IPHONE
    ^
main.cpp:2666:11: warning: 'vfork' is deprecated: Use posix_spawn or fork [-Wdeprecated-declarations]
    _proc=vfork();
          ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/unistd.h:604:1: note: 'vfork' has been explicitly marked deprecated here
__deprecated_msg("Use posix_spawn or fork")
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/cdefs.h:208:48: note: expanded from macro '__deprecated_msg'
        #d3 warnings generated.
efine __deprecated_msg(_msg) __attribute__((__deprecated__(_msg)))
                                                      ^
Program Exit Code: 65280
Done.
 

dawlane

Well-known member
CX Code Contributor
Tutorial Author
Joined
Jun 21, 2017
Messages
937
I suspect it needs to be changed.
warning: 'TARGET_OS_IPHONE' is not defined, evaluates to 0
If your code uses 'TARGET_OS_IPHONE', then the issue is with how you have implemented it. But if your code doesn't use 'TARGET_OS_IPHONE', then it should be raised as a bug.

With your own code. Stick to the official.
Code:
#If TARGET="ios"
    ' iOS specific code here
#Else
    ' Other non specific iOS code here
#Endif
warning: 'vfork' is deprecated: Use posix_spawn or fork
This is a Unix process function to start a child process. The warning is stating that vfork is not a good idea to keep using, due to the fact that vfork will use the same address space as the parent process, thus meaning that if the child process misbehaves; then the parent process is at risk of crashing.

@bosh77
The example I posted in post 12 has been updated a bit. At some point I'll put another example on how to do this in a glfw desktop target.
 

Wingnut

Well-known member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
1,196
I use the latest of everything and still the same but I don't have my certificate to compile for ios added yet to xcode so that's part of the error of course.

I tried to compile for C++ not iphone though so it might be a bug.
 
Top Bottom