Contents

Dynamically loading Object Icon programs.

Dynamically loading Object Icon code

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

Some points to note.

Contents