User Tools

Site Tools


dynamic-loading

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
dynamic-loading [2018/02/09 04:49]
barryfp
dynamic-loading [2019/07/24 13:17] (current)
barryfp
Line 53: Line 53:
 ====== Dynamic interface lookup ====== ====== Dynamic interface lookup ======
  
-Once we've loaded a component into main memory, giving us a generic IDC reference, we can query it for interfaces that it provides as well as interfaces that it requires. Interface querying basically ​ works in the same way for both of these variants but for now we'll just focus on the provided ones.+Once we've loaded a component into main memory, giving us a generic IDC reference, we can query it for interfaces that it provides as well as interfaces that it requires. Interface querying basically works in the same way for both of these variants but for now we'll just focus on the provided ones.
  
-We query a provided interface using either ​the notation:+We query a provided interface using the IDC function:
  
-<code d>​com ​:< InteraceType</​code>​ +<code d>com.hasProvides("​InterfaceType"​)</​code>​
- +
-in cases where we want to supply the locally-known type of the interface, or: +
- +
-<code d>com :< "​InterfaceType"</​code>​ +
- +
-in cases where we just want to provide the name of the interface, rather than the complete type. +
- +
-Both of these operations will return ''​null''​ if no interface of that type / name could be found.+
  
 ====== Dynamic instantiation ====== ====== Dynamic instantiation ======
Line 71: Line 63:
 Putting everything together, we interact with a dynamically loaded component by instantiating an object of a type matching one of that component'​s provided interfaces. This is very similar to the way in which we normally instantiate objects, except that we specify the interface with which to complete the instantiation. Putting everything together, we interact with a dynamically loaded component by instantiating an object of a type matching one of that component'​s provided interfaces. This is very similar to the way in which we normally instantiate objects, except that we specify the interface with which to complete the instantiation.
  
-<code d>Adder a = new Adder() from com :< Adder</​code>​+<code d>Adder a = new Adder() from com</​code>​
  
 The "​from"​ notation here enables us to specify the particular interface, of a particular component, with which to instantiate the object. The "​from"​ notation here enables us to specify the particular interface, of a particular component, with which to instantiate the object.
Line 86: Line 78:
  IDC com = loader.load("​MyAdder.o"​)  IDC com = loader.load("​MyAdder.o"​)
   
- Adder a = new Adder() from com :< Adder+ Adder a = new Adder() from com
   
  int q = a.add(5, 6)  int q = a.add(5, 6)
Line 192: Line 184:
 In the main method, the array ''​results''​ now contains a list of relative file paths to components that implement each required interface, searching both locally and in the standard library. You can also use the ''​composition.Search''​ API to search in specific directories. In the main method, the array ''​results''​ now contains a list of relative file paths to components that implement each required interface, searching both locally and in the standard library. You can also use the ''​composition.Search''​ API to search in specific directories.
  
-Now that we've found some options, we can wire each dependency up to the first option on this list, by loading the component that we'd like to connect to and then using ''​dana.rewire'':​+Now that we've found some options, we can wire each dependency up to the first option on this list, by loading the component that we'd like to connect to and then using the IDC function ​''​wire'':​
  
 <code d> <code d>
Line 215: Line 207:
                                        
                    IDC ncom = loader.load(results[i].string)                    IDC ncom = loader.load(results[i].string)
-                   dana.rewire(com :> dependencies[i].alias,​ ncom :< dependencies[i].alias)+                   com.wire(dependencies[i].alias,​ ncomdependencies[i].alias)
                    }                    }
   
dynamic-loading.1518169789.txt.gz · Last modified: 2018/02/09 04:49 by barryfp