Advertisement
Guest User

Untitled

a guest
Feb 13th, 2012
602
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. #include <iostream>
  2. #include "eel2/ns-eel.h"
  3.  
  4. using namespace std;
  5.  
  6. // these functions must be compiled in but
  7. // actual mutex locking omitted here for brevity in this example
  8. void NSEEL_HOSTSTUB_EnterMutex() {}
  9. void NSEEL_HOSTSTUB_LeaveMutex() {}
  10.  
  11. int main()
  12. {
  13.     NSEEL_VMCTX vm=NSEEL_VM_alloc(); // create virtual machine
  14.     double* variable_x=NSEEL_VM_regvar(vm,"x"); // register a variable into vm to get a value out
  15.     double* variable_y=NSEEL_VM_regvar(vm,"y"); // register another variable into vm
  16.     double* variable_t=NSEEL_VM_regvar(vm,"t"); // etc
  17.     char codetext[65536]; // this needs to be larger than might be anticipated as eel2 uses this buffer as workspace
  18.     memset(codetext,0,65536);
  19.     strcpy(codetext,"x=2+2;y=sin(t);");
  20.     NSEEL_CODEHANDLE codehandle=NSEEL_code_compile(vm,codetext,0); // compile code
  21.     NSEEL_code_execute(codehandle); // execute code
  22.     cout << "variable x is "<<*variable_x<<std::endl;
  23.     // execute the already compiled code many times
  24.     for (int i=0;i<16;i++)
  25.     {
  26.         *variable_t=i;
  27.         NSEEL_code_execute(codehandle);
  28.         cout << "t="<<*variable_t<<" y="<<*variable_y<<std::endl;
  29.     }
  30.     // especially in production code, remember to deallocate the VMs and codehandles as appropriate
  31.     NSEEL_code_free(codehandle);
  32.     NSEEL_VM_free(vm);
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement