Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "eel2/ns-eel.h"
- using namespace std;
- // these functions must be compiled in but
- // actual mutex locking omitted here for brevity in this example
- void NSEEL_HOSTSTUB_EnterMutex() {}
- void NSEEL_HOSTSTUB_LeaveMutex() {}
- int main()
- {
- NSEEL_VMCTX vm=NSEEL_VM_alloc(); // create virtual machine
- double* variable_x=NSEEL_VM_regvar(vm,"x"); // register a variable into vm to get a value out
- double* variable_y=NSEEL_VM_regvar(vm,"y"); // register another variable into vm
- double* variable_t=NSEEL_VM_regvar(vm,"t"); // etc
- char codetext[65536]; // this needs to be larger than might be anticipated as eel2 uses this buffer as workspace
- memset(codetext,0,65536);
- strcpy(codetext,"x=2+2;y=sin(t);");
- NSEEL_CODEHANDLE codehandle=NSEEL_code_compile(vm,codetext,0); // compile code
- NSEEL_code_execute(codehandle); // execute code
- cout << "variable x is "<<*variable_x<<std::endl;
- // execute the already compiled code many times
- for (int i=0;i<16;i++)
- {
- *variable_t=i;
- NSEEL_code_execute(codehandle);
- cout << "t="<<*variable_t<<" y="<<*variable_y<<std::endl;
- }
- // especially in production code, remember to deallocate the VMs and codehandles as appropriate
- NSEEL_code_free(codehandle);
- NSEEL_VM_free(vm);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement