Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Aug 13 2016 03:25
    @PeterWAWood banned @Vexercizer
GiuseppeChillemi
@GiuseppeChillemi
@hiiamboris thank you, the dialect is nice. Finally I am there.
VaZub
@vazub_gitlab

What does "freestanding compile target" mean? You can compile EXEs with no dependencies today.

I might be mistaken, but I believe there is an inherent dependency on C library by default, at least for POSIX targets that I looked into. Would be interested to learn more whether Red/System actually allows to omit this dependency.

VaZub
@vazub_gitlab
Answering my own question above - apparently specifying the --no-runtime compiler option does the trick - the executable gets produced with no lib or system dependencies whatsoever. Will dig deeper then)
Gregg Irwin
@greggirwin
:+1: Sorry nobody else was able to jump in, but glad you figured it out.
Dan Kokenge
@DanKokenge_twitter
Ok! Being new to RED, does this mean I could put a exe on a cloud disk. Users could then run the exe. It would basically do what what you normally do with html and client/server. That would be amazing.
VaZub
@vazub_gitlab
put a exe on a cloud disk. Users could then run the exe
Not sure what exactly you mean here. Cloud storage is not an executable environment - it doesn't have the facilities to run files.
Petr Krenzelok
@pekr
Exactly - such user will be most probably able to download such file, but some protective measures (antivirus protection) might step-in and prevent this. The cloud storage would have to be remotely mounted as a local/network drive, which might be possible e.g. using WebDav, but not sure ...
Dan Kokenge
@DanKokenge_twitter
You'll have to forgive me, I just started reading about RED/REBOL. What I'm trying to do is bypass the client/server type web app. Instead of the client clicking on some link on a home page and getting served up html/js, I keep trying to to come up with some way they can run programs direct on their computer from exe's or interpreted source code served to them from the server. This may be a stupid idea, but if Rebol could somehow get loaded to the user, it could do what JS does on the client side. They then load only source code from the server to be executed. If it could be done, it would make writing client/ server apps as if they were local and reduce development time. Maybe RED has a small engine that interprets code? -- Just exploring ideas?? Thanks for the help..
Petr Krenzelok
@pekr
With Red/Rebol, of course you can run remote scripts using do http://my-domain.com/my-script.red, but not executables directly. You can eventually download the executable using Red, stored it locally and launch it using call. But really beware the security ...
Gregg Irwin
@greggirwin
@DanKokenge_twitter I think I mentioned this somewhere recently. You need an environment of some kind, just as with any EXE you can get from the net. In Red's case, you can build standalone EXEs, but you're going to run into the same limitations you would with apps built in any other tool. The other thing you can do is write a launcher that let's people select the remote Red content and executes it locally.
e.g. look at this
You can also do it so the remote content runs outside the context of your launcher.
DVL333
@DVL333
Is there a way to convert Red code to R/S code? I mean, you have a file with Red code and you want a file with R/S code.
Gregg Irwin
@greggirwin
Red compiles to R/S, but they are different languages with different type systems (for example). If you want to convert code, to optimize it, there's no translator for that today.
DVL333
@DVL333
ok, see you. Thanks Gregg.
hiiamboris
@hiiamboris
Try red -c -v 3 script.red >output.reds
hiiamboris
@hiiamboris
that's just looking under the sheets though, won't help optimize anything ;)
DVL333
@DVL333
@hiiamboris Thanks!
Dmitry Bubnenkov
@bubnenkoff
Red []
#system [
    #import [
           "kernel32.dll" stdcall [
               process-id?: "GetCurrentProcessId" [
                   return: [integer!]
               ]
        ] 
    ]
    _pid: func[return: [integer!]] [return process-id?]
]

get-pid: routine [ /local pid [integer!] return: [integer!] ] [
        pid: _pid
        return pid
    ]

view [button [probe get-pid]]
I am getting error:
 invalid definition for function exec/get-pid: [return: [integer!]]
hiiamboris
@hiiamboris
try moving return: to before /local
Dmitry Bubnenkov
@bubnenkoff
Red []
#system [
    #import [
           "kernel32.dll" stdcall [
               process-id?: "GetCurrentProcessId" [
                   return: [integer!]
               ]
        ] 
    ]
    _pid: func[return: [integer!]] [return process-id?]
]

get-pid: routine [ return: [integer!] /local pid [integer!] ] [
        pid: _pid
        return pid
    ]

view [button [probe get-pid]]
Work! Thanks!
Dmitry Bubnenkov
@bubnenkoff
Can r/s can be placed inside .red file?
hiiamboris
@hiiamboris
Extension is ignored
Gregg Irwin
@greggirwin
But if you have only R/S in a file, using %.reds makes that clear and helps people.
Dmitry Bubnenkov
@bubnenkoff
I can compile code above only if it's placed in main (app.red(s)) file. If I am placing it in another file and than do:
#include %foo.reds I am getting compilation error:
Compilation Error: undefined symbol: _pid
Dmitry Bubnenkov
@bubnenkoff
I need to send message to Red process (actually simple ping it to trigger function). I have read docs about WinAPI and found function PostThreadMessage. How to handle it's from Red? Or maybe there is any better ways?
hiiamboris
@hiiamboris
same as you handle GetCurrentProcessId
if Red supports this event, it will handle it
simplest way of communication though would be reading and writing a file
hiiamboris
@hiiamboris

Compilation Error: undefined symbol: _pid

Can't reproduce

Dmitry Bubnenkov
@bubnenkoff

Compilation Error: undefined symbol: _pid

Can't reproduce

Sorry I forgot to mention that -e flag is needed .Try to compile with -c -e to get the errror

hiiamboris
@hiiamboris
Ah. Makes sense. -e replaces #include with do so we should expect that
Please file an issue. Though this is how it currently works, it also raises important design questions.
Dmitry Bubnenkov
@bubnenkoff
@hiiamboris done. but with do impossible to use R/S code Internal Error: contains Red/System code which requires compilation
Dmitry Bubnenkov
@bubnenkoff

@hiiamboris could you help me with wrapping WinAPI? According docs https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getmessage I did this:

Red []

view [button [probe get-pid]]

#system [
    #import [
           "kernel32.dll" stdcall [
               process-id?: "GetCurrentProcessId" [
                   return: [integer!]
               ]
               get-msg: "GetMessage" [
                   msg    [pointer!] ; A pointer to an MSG structure that receives message information from the thread's message queue.
                   hWnd   [integer!] ; If hWnd is NULL, retrieves messages for any window that belongs to the current thread
                   wMsgFilterMin    [integer!]
                   wMsgFilterMax    [integer!]
                   return: [logic!]
               ]               
        ] 
    ]

    max-size: 128
    msg: malloc max-size 

    get-msg msg null 0 0    

    _pid: func[return: [integer!]] [return process-id?]

    print msg
    print _pid

]

get-pid: routine [ return: [integer!] /local pid [integer!] ] [
        pid: _pid
        return pid
    ]

;get-msg: routine [ return: [c-string!] /local msg [c-string!] ] [
;        msg: _msg
;        return msg
;    ]

But I am getting compilation error:

*** Compilation Error: invalid definition for function exec/get-msg: [
    msg [pointer!]
    hWnd [integer!]
    wMsgFilterMin [integer!]
    wMsgFilterMax [integer!]
    return: [logic!]
]
hiiamboris
@hiiamboris
there is no pointer! type in R/S
there is pointer! [integer!] (or int-ptr!) and alikes
Dmitry Bubnenkov
@bubnenkoff
@hiiamboris Could you look at my code please. Now it's compile but or I am sending message wrong or there is should be some additional logic to handle it:
Red []

view [button [probe get-pid]]

#system [
    #import [
           "kernel32.dll" stdcall [
               process-id?: "GetCurrentProcessId" [
                   return: [integer!]
               ]
               get-msg: "GetMessage" [
                   msg    [integer!] ; A pointer to an MSG structure that receives message information from the thread's message queue.
                   hWnd   [integer!] ; If hWnd is NULL, retrieves messages for any window that belongs to the current thread
                   wMsgFilterMin    [integer!]
                   wMsgFilterMax    [integer!]
                   return: [logic!]
               ]   
        ] 
           "msvcrt.dll" cdecl [
               malloc: "malloc" [
                   size    [integer!]
                   return: [c-string!]
               ]
               release: "free" [
                   block   [c-string!]
               ]
           ]
    ]

    _pid: func[return: [integer!]] [return process-id?]

    print _pid

]

    max-size: 128
    msg: malloc max-size 

    get-msg msg null 0 0    
    print msg

get-pid: routine [ return: [integer!] /local pid [integer!] ] [
        pid: _pid
        return pid
    ]

;get-msg: routine [ return: [c-string!] /local msg [c-string!] ] [
;        msg: _msg
;        return msg
;    ]
hiiamboris
@hiiamboris
I don't even know what you're trying to do.
The problem I see is that Red has it's own event function (aka WndProc), and it's calling GetMessage on it's own. It'll be a race: your GetMessage against Red's one.
Dmitry Bubnenkov
@bubnenkoff
I am tying to send message from other process to Red with calling SendMessage and accept it in Red with GetMessage
hiiamboris
@hiiamboris
Gimme the bigger picture. You're doing this for what?
Dmitry Bubnenkov
@bubnenkoff
I am running processing of data with Red app. Every app on start sending own PID to monitoring service. I want to be able "ping" red app every n minutes to call function that will send some app metrics like: "I am not hanging I am working"
hiiamboris
@hiiamboris
I see.
Let me think..
Try sending this message from your service. If I understand correctly, Red will handle it for you, you should not need any code in your Red apps.
If Red app doesn't answer, it probably hang.
Gregg Irwin
@greggirwin
@bubnenkoff It sounds like very coarse timed IPC. For this I've often used files as the mechanism in the past. You can write status files from each process and the monitor just reads them. You can do more than just I'm Alive then as well. What is it processing, how far along, etc. I've also done it with direct TCP, IOS link messages in that env, and 0MQ. Oh, and DDE in the oooooold days. Once we have FFI at the Red level, I will probably port my 0MQ lib. In any case, files are an easy and flexible solution.
Maciej Łoziński
@loziniak
Hello. If I return pointer to data from imported C function, is there a possibility to deallocate the memory on Red side, for example by Garbage Collector? Perhaps it can be done on Red/System level? I know I can implement cleaning the memory on the C side, by providing a accompanying function, but I'd like to avoid it.
hiiamboris
@hiiamboris
free function in R/S is imported from libc