I put some functions' defination in a file named "funcs.red", functions in which would be invoked by main program. Here is the example of "funcs.red":
Red []
myadd: func [x y] [x + y]
The content of main program("main.red") is:
Red [needs: view]
do %funcs.red
view [t: text "result" button "myadd" [t/text: to-string myadd 1 2]]
Both "main.red" and "funcs.red" are in the same path.
In red console, the "main.red" works right as expected by do %funcs.red do %main.red
. Then I tried to compile "main.red":
red -r -t windows main.red
but it failed and an error message was given:
Compilation Error: undefined word myadd...
So, in Red, how to link the main script with another script when compiling?
To reference other red sources at compile-time, you should use #include
. When you use do
, it looks for that file, reads and interprets it at run-time.
#include %funcs.red
You can still use #include
when interpreting a script too. The interpreter will treat it the same as do
in that case.