c_rootobj.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include <precomp.h>
  2. #include <api/script/scriptobj.h>
  3. #include <api/script/objcontroller.h>
  4. #include "c_rootobj.h"
  5. C_RootObject::C_RootObject(ScriptObject *o)
  6. {
  7. inited = 0;
  8. obj = NULL;
  9. C_hook(o);
  10. }
  11. C_RootObject::C_RootObject()
  12. {
  13. inited = 0;
  14. obj = NULL;
  15. }
  16. void C_RootObject::C_hook(ScriptObject *o)
  17. {
  18. ASSERT(!inited);
  19. obj = o;
  20. if (count++ == 0) {
  21. getclassname_id = WASABI_API_MAKI->maki_addDlfRef(o->vcpu_getController(), L"getClassName", this);
  22. notify_id = WASABI_API_MAKI->maki_addDlfRef(o->vcpu_getController(), L"notify", this);
  23. }
  24. inited=1;
  25. }
  26. C_RootObject::~C_RootObject()
  27. {
  28. if (!inited) return;
  29. WASABI_API_MAKI->maki_remDlfRef(this);
  30. //count--;
  31. }
  32. ScriptObject *C_RootObject::getScriptObject()
  33. {
  34. ASSERT(inited);
  35. return obj;
  36. }
  37. const wchar_t *C_RootObject::getClassName()
  38. {
  39. ASSERT(inited);
  40. return GET_SCRIPT_STRING(WASABI_API_MAKI->maki_callFunction(obj, getclassname_id, NULL));
  41. }
  42. void C_RootObject::notify(const wchar_t *a, const wchar_t *b, int c, int d)
  43. {
  44. ASSERT(inited);
  45. scriptVar _a = MAKE_SCRIPT_STRING(a);
  46. scriptVar _b = MAKE_SCRIPT_STRING(b);
  47. scriptVar _c = MAKE_SCRIPT_INT(c);
  48. scriptVar _d = MAKE_SCRIPT_INT(d);
  49. scriptVar *params[4]={&_a, &_b, &_c, &_d};
  50. WASABI_API_MAKI->maki_callFunction(obj, notify_id, params);
  51. }
  52. int C_RootObject::getclassname_id=0;
  53. int C_RootObject::notify_id=0;
  54. int C_RootObject::inited=0;
  55. int C_RootObject::count=0;