|
|
Label: ♦english
♦miscellaneous
Pompei2
created at Sunday, 2011-01-30, 13:45:42
4 Replies, 1243 Hits
Hello,
I have the following kind of code: ComponentManager.dao:
load Component;
class ComponentManager { private var _components : map<string, map<int, Component>> } Component.dao:
load ComponentManager;
interface Component { sub observe(mgr : ComponentManager) sub act(mgr : ComponentManager) } You can see the cyclic dependency: ComponentManager holds a list of Components, while the Components should have a callback that gets the ComponentManager as parameter. Unfortunately, this code won't compile (in World.dao, I do "load ComponentManager;"), because when dao gets to Component.dao, it doesn't know the type "ComponentManager" yet:
[[ERROR]] in file "/windows/Xchange/projects/component-system-prototype-fail1/CompSys/Component.dao":
My question is, how could I possibly solve that? And in a more general way, how to work around such a cyclic dependency in dao? Is there something like forward declaration in dao? Or maybe you have a suggestion to restructure my code?At line 7 : Invalid parameter list for --- " observe "; [[ERROR]] in file "/windows/Xchange/projects/component-system-prototype-fail1/CompSys/Component.dao": At line 40 : Invalid interface definition --- " interface Component { routine observe ... "; [[ERROR]] in file "/windows/Xchange/projects/component-system-prototype-fail1/CompSys/ComponentManager.dao": At line 3 : loading failed; [[ERROR]] in file "/windows/Xchange/projects/component-system-prototype-fail1/World.dao": At line 3 : loading failed; [[ERROR]] in file "/windows/Xchange/projects/component-system-prototype-fail1/main.dao": At line 3 : loading failed; Comments
Nightwalker commented at Sunday, 2011-01-30, 14:59:12
Nightwalker modified at Sunday, 2011-01-30, 15:31:42
I encountered similar situation too. You can just define additional interface for ComponentManager in Component.dao ; use it as parameter type for Component 's methods, and then bind that interface to the actual class in ComponentManager.dao . Then you don't need to load ComponentManager.dao in Component.dao , and cross-dependency is eliminated :) However, the interface for ComponentManager will still be unable to explicitly refer to the interface Component (untyped arguments are needed for that instead).
fu commented at Sunday, 2011-01-30, 22:06:07
is now supported for both class and interface:)
Pompei2 commented at Sunday, 2011-01-30, 22:10:18
Pompei2 modified at Sunday, 2011-01-30, 22:13:12
Wow cool, thanks a bunch!
Edit: I see in the example files, that now you declared the routine inside the class but defined it outside the class (C++-style), was that supported since ever, or did you just add that?
fu commented at Tuesday, 2011-02-01, 01:58:18
Define methods outside of class body has been supported for quite sometime:)
|
fu: A little bit game development in Dao! Thanks to ClangDao, it has become very easy to create bindings for C/ C++ libraries. The latest one i ... (May.14,07:08) dao: Dao 1.2 Beta1 is released! After a very long time of development, the first beta release for Dao 1.2 is finally available ( http ... (May.06,23:37) fu: ... Just to mention: a couple of demos (including the 2000 line one) has been successfully ported to IPho ... (May.19,02:43) fu: ... Yes, it is getting mature, and more libraries and modules are coming out, hehe:) For GameKit, unfor ... (May.19,02:38) Pompei2: ... This is cool news and really shows that ClangDao is getting mature, thumbs up. Too bad for this litt ... (May.18,09:17) fu: ... Not completely, but mostly. New revisions will be regularly pushed to the repository on google code ( ... (May.08,22:38) Pompei2: ... If I understand it correctly, you want to completely switch? If so then: (May.08,08:46) |