MyNativePlugin.cpp 704 B

123456789101112131415161718192021222324252627282930313233
  1. #define ATOMIC_PLUGIN_MAIN
  2. #include "AtomicPlugin.h"
  3. extern "C"
  4. {
  5. static int js_getAnswer(duk_context* ctx)
  6. {
  7. duk_push_number(ctx, 42);
  8. return 1;
  9. }
  10. // plugin init is a duk cfunction itself, so we can pcall the import
  11. int PLUGIN_EXPORT_API atomic_plugin_init(duk_context* ctx)
  12. {
  13. // exports object at 0
  14. if (!duk_is_object(ctx, 0))
  15. {
  16. duk_push_boolean(ctx, 0);
  17. return 1;
  18. }
  19. // export out native functions
  20. duk_push_c_function(ctx, js_getAnswer, 0);
  21. duk_put_prop_string(ctx, -2, "getAnswer");
  22. // and return success
  23. duk_push_boolean(ctx, 1);
  24. return 1;
  25. }
  26. }