Advertisement
Guest User

Untitled

a guest
May 15th, 2019
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. init :
  2.  
  3. js_State *ctx = js_newstate(NULL,NULL,JS_STRICT);
  4. if (!ctx)
  5. {
  6.      printf("js_State init error.\n");
  7.      exit(-1);
  8. }
  9. js_getglobal(ctx,"Object");
  10. js_getproperty(ctx, -1, "prototype");
  11. js_newuserdata(ctx,"jsState",new jsState(),0);
  12. js_newcfunction(ctx,native_print,"print", 1 /*nargs*/);
  13. js_setglobal(ctx,"print");
  14. js_dostring(ctx,job_text.c_str());
  15.  
  16.  
  17. void jsProcessor::native_print(js_State  *ctx)
  18. {
  19.     jsState *j = (jsState *)js_touserdata(ctx,0,"jsState");
  20.     printf("%s\n",js_tostring(ctx, 1));
  21.     js_pushundefined(ctx);
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement