If you want the self reference of the resulting actor, we have a syntax for that:
actor class Client() = self {
...
}
EDIT: Ah, I see you want the creator of the new canister. I don’t think that is conveyed by the protocol. But you can probably get hold of the controllers list.
In this case I cannot get canister id anywhere other than inside that actor class.
For example I want pass current canister id to class or func from another file:
// a.mo
class A1(x : actor{}) {};
class A2(x : Principal) {};
class A3(x : () -> Principal) {};
// main.mo
actor class Client() = self {
let a1 = A1(self); // error "cannot use self before self has been defined"
let a2 = A2(Principal.fromActor(self)); // error "cannot use self before self has been defined"
func getCanisterId() : Principal = Principal.fromActor(self);
let a3 = A3(getCanisterId); // error "cannot use getCanisterId before self has been defined"
}
I recall discussing this cannot use self error with @claudio earlier. IIRC we concluded that this is a definedness analysis bug (infelicity) in Motoko, and the self binding should be available in the initialisation code of the actor.