Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var logfunc1:shared_ptr[DLLFunc];
- var logfunc2:shared_ptr[DLLFunc];
- function init(logfunc1:ref shared_ptr[DLLFunc], logfunc2:ref shared_ptr[DLLFunc]){
- *logfunc1 = shared_ptr::new(DLLFunc::load("stdio", "_print"));
- *logfunc2 = logfunc1;
- }
- function log(logfunc:ref shared_ptr[DLLFunc], message:string){
- (*logfunc)->invoke(message.get_data());
- }
- function update_logger(logfunc:ref shared_ptr[DLLFunc], func:ref DLLFunc){
- **logfunc = *func;
- }
- function main(){
- init(&logfunc1, &logfunc2);
- //borrow for logfunc1 is no more
- // copy is free to borrow global logfunc1
- update_logger(&logfunc2, DLLFunc::load("kyfoo", "_print"));
- }
- instance Copy DLLFunc {
- function copy(target:out Bar, source:ref Bar){
- target->dllhandle = dup_dll(source->dllhandle);
- log(&logfunc1, "DLL Handle duped");
- target->funchandle = dup_funchandle(
- source->dllhandle,
- source->funchandle,
- target->dllhandle
- );
- log(&logfunc1, "Func Handle duped");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement