Advertisement
tinyevil

Untitled

Jul 29th, 2018
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. var logfunc1:shared_ptr[DLLFunc];
  2. var logfunc2:shared_ptr[DLLFunc];
  3.  
  4. function init(logfunc1:ref shared_ptr[DLLFunc], logfunc2:ref shared_ptr[DLLFunc]){
  5.     *logfunc1 = shared_ptr::new(DLLFunc::load("stdio", "_print"));
  6.     *logfunc2 = logfunc1;
  7. }
  8.  
  9. function log(logfunc:ref shared_ptr[DLLFunc], message:string){
  10.     (*logfunc)->invoke(message.get_data());
  11. }
  12.  
  13. function update_logger(logfunc:ref shared_ptr[DLLFunc], func:ref DLLFunc){
  14.     **logfunc = *func;
  15. }
  16.  
  17. function main(){
  18.     init(&logfunc1, &logfunc2);
  19.    
  20.     //borrow for logfunc1 is no more
  21.    
  22.     // copy is free to borrow global logfunc1
  23.     update_logger(&logfunc2, DLLFunc::load("kyfoo", "_print"));
  24. }
  25.  
  26. instance Copy DLLFunc {
  27.     function copy(target:out Bar, source:ref Bar){
  28.         target->dllhandle = dup_dll(source->dllhandle);
  29.         log(&logfunc1, "DLL Handle duped");
  30.         target->funchandle = dup_funchandle(
  31.             source->dllhandle,
  32.             source->funchandle,
  33.             target->dllhandle
  34.         );
  35.         log(&logfunc1, "Func Handle duped");
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement