Object Icon includes a small enhancement to MT Icon which allows procedures and classes to be loaded and invoked dynamically from other icode files (ie executable files created by the linker).
To illustrate how this works, consider the following simple source file:-
import io
invocable X, p
class X()
public hello()
write("Hello")
end
end
procedure p()
write("Hello again")
end
procedure main()
end
If this were in the file abc.icn
, then it could be compiled with the command oit abc.icn
. Then its symbols could be loaded and used dynamically as follows :-
import io, lang
procedure main()
local prog, x
prog := Prog.load("abc") | stop("Couldn't load")
# Create an instance of X, call hello method
x := Prog.get_global("X", prog)()
x.hello()
# Call procedure p
Prog.get_global("p", prog)()
end
main
procedure. It also needs to declare the procedure and class as invocable, so that the linker doesn’t discard them as unreferenced symbols.Class.for_name("X", prog)()
.proc("p",,prog)()