makiapi.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. #include "precomp.h"
  2. #include "makiapi.h"
  3. #include "../../studio/api.h"
  4. #include "../../bfc/api/api_maki.h"
  5. #include "../../studio/script/vcpu.h"
  6. #include "../../studio/script/objecttable.h"
  7. #include "../../studio/script/scriptmgr.h"
  8. #include "../../studio/script/script.h"
  9. #include "../../common/script/scriptobj.h"
  10. api_maki *makiApi = NULL;
  11. ScriptApi::ScriptApi() {
  12. ObjectTable::loadExternalClasses();
  13. VCPU::scriptManager = new ScriptObjectManager();
  14. }
  15. ScriptApi::~ScriptApi() {
  16. delete VCPU::scriptManager;
  17. VCPU::scriptManager = NULL;
  18. VCPU::shutdown();
  19. ObjectTable::unloadExternalClasses();
  20. }
  21. void ScriptApi::maki_pushObject(void *o) {
  22. VCPU::pushObject(o);
  23. }
  24. void ScriptApi::maki_pushInt(int i) {
  25. VCPU::pushInt(i);
  26. }
  27. void ScriptApi::maki_pushBoolean(int b) {
  28. VCPU::pushBoolean(b);
  29. }
  30. void ScriptApi::maki_pushFloat(float f) {
  31. VCPU::pushFloat(f);
  32. }
  33. void ScriptApi::maki_pushDouble(double d) {
  34. VCPU::pushDouble(d);
  35. }
  36. void ScriptApi::maki_pushString(const char *s) {
  37. VCPU::pushString(s);
  38. }
  39. void ScriptApi::maki_pushAny(scriptVar v) {
  40. VCPU::push(v);
  41. }
  42. void ScriptApi::maki_pushVoid() {
  43. VCPU::pushVoid();
  44. }
  45. void *ScriptApi::maki_popObject() {
  46. return VCPU::popObject();
  47. }
  48. int ScriptApi::maki_popInt() {
  49. return VCPU::popInt();
  50. }
  51. bool ScriptApi::maki_popBoolean() {
  52. return VCPU::popBoolean();
  53. }
  54. float ScriptApi::maki_popFloat() {
  55. return VCPU::popFloat();
  56. }
  57. double ScriptApi::maki_popDouble() {
  58. return VCPU::popDouble();
  59. }
  60. const char *ScriptApi::maki_popString() {
  61. return VCPU::popString();
  62. }
  63. scriptVar ScriptApi::maki_popAny() {
  64. return VCPU::pop().v;
  65. }
  66. void ScriptApi::maki_popDiscard() {
  67. VCPU::popDiscard();
  68. }
  69. const char *ScriptApi::maki_getFunction(int dlfid, int *nparams, ScriptObjectController **p) {
  70. return ObjectTable::getFunction(dlfid, nparams, p);
  71. }
  72. int ScriptApi::maki_addDlfRef(ScriptObjectController *o, const char *function_name, void *host) {
  73. return ObjectTable::dlfAddRef(o, function_name, host);
  74. }
  75. void ScriptApi::maki_remDlfRef(void *host) {
  76. ObjectTable::dlfRemRef(host);
  77. }
  78. void ScriptApi::maki_addDlfClassRef(ScriptObjectController *o, void *host) {
  79. ObjectTable::dlfAddClassRef(o, host);
  80. }
  81. scriptVar ScriptApi::maki_callFunction(ScriptObject *o, int dlfid, scriptVar **params) {
  82. return ObjectTable::callFunction(o, dlfid, params);
  83. }
  84. scriptVar ScriptApi::maki_triggerEvent(ScriptObject *o, int dlfid, int np, int scriptid) {
  85. scriptVar v = MAKE_SCRIPT_OBJECT(o);
  86. return VCPU::executeEvent(v, dlfid, np, scriptid);
  87. }
  88. ScriptObject *ScriptApi::maki_instantiate(GUID classguid) {
  89. int classid = ObjectTable::getClassFromGuid(classguid);
  90. if (classid == -1) return NULL;
  91. return ObjectTable::instantiate(classid);
  92. }
  93. void ScriptApi::maki_destroy(ScriptObject *o) {
  94. ObjectTable::destroy(o);
  95. }
  96. void *ScriptApi::maki_encapsulate(GUID classguid, ScriptObject *o) {
  97. int classid = ObjectTable::getClassFromGuid(classguid);
  98. if (classid == -1) return NULL;
  99. return ObjectTable::encapsulate(classid, o);
  100. }
  101. void ScriptApi::maki_deencapsulate(GUID classguid, void *o) {
  102. int classid = ObjectTable::getClassFromGuid(classguid);
  103. if (classid == -1) return;
  104. ObjectTable::deencapsulate(classid, o);
  105. }
  106. ScriptObjectController *ScriptApi::maki_getController(GUID scriptclass) {
  107. return ObjectTable::getController(scriptclass);
  108. }
  109. int ScriptApi::maki_createOrphan(int type) {
  110. return VCPU::createOrphan(type);
  111. }
  112. void ScriptApi::maki_killOrphan(int id) {
  113. VCPU::killOrphan(id);
  114. }
  115. int ScriptApi::maki_getScriptInt(scriptVar v) {
  116. return SOM::makeInt(&v);
  117. }
  118. bool ScriptApi::maki_getScriptBoolean(scriptVar v) {
  119. return SOM::makeBoolean(&v);
  120. }
  121. float ScriptApi::maki_getScriptFloat(scriptVar v) {
  122. return SOM::makeFloat(&v);
  123. }
  124. double ScriptApi::maki_getScriptDouble(scriptVar v) {
  125. return SOM::makeDouble(&v);
  126. }
  127. const char *ScriptApi::maki_getScriptString(scriptVar v) {
  128. ASSERT(v.type == SCRIPT_STRING);
  129. return v.data.sdata;
  130. }
  131. ScriptObject *ScriptApi::maki_getScriptObject(scriptVar v) {
  132. ASSERT(!SOM::isNumeric(&v) && v.type != SCRIPT_STRING);
  133. return v.data.odata;
  134. }
  135. scriptVar ScriptApi::maki_updateDlf(maki_cmd *cmd, int *dlfid, int *linkcount) {
  136. switch (cmd->cmd) {
  137. case MAKI_CMD_ADDREF:
  138. (*linkcount)++;
  139. break;
  140. case MAKI_CMD_REMREF:
  141. (*linkcount)--;
  142. ASSERT(*linkcount >= 0);
  143. if (*linkcount == 0)
  144. *dlfid = -1;
  145. break;
  146. case MAKI_CMD_SETDLF:
  147. ASSERT(*dlfid == -1);
  148. *dlfid = cmd->id;
  149. break;
  150. case MAKI_CMD_GETDLF:
  151. cmd->id = *dlfid;
  152. break;
  153. }
  154. RETURN_SCRIPT_VOID
  155. }
  156. void ScriptApi::maki_setObjectAtom(const char *atomname, ScriptObject *object) {
  157. VCPU::setAtom(atomname, object);
  158. }
  159. ScriptObject *ScriptApi::maki_getObjectAtom(const char *atomname) {
  160. return VCPU::getAtom(atomname);
  161. }
  162. #ifdef WASABI_COMPILE_WND
  163. ScriptObject *ScriptApi::maki_findObject(const char *name) {
  164. return ScriptObjectManager::findObject(name);
  165. }
  166. #endif
  167. void ScriptApi::vcpu_addScriptObject(ScriptObject *o) {
  168. SystemObject::addScriptObject(o);
  169. }
  170. void ScriptApi::vcpu_removeScriptObject(ScriptObject *o) {
  171. SystemObject::removeScriptObject(o);
  172. }
  173. int ScriptApi::vcpu_getCacheCount() {
  174. return Script::getCacheCount();
  175. }
  176. int ScriptApi::vcpu_isValidScriptId(int id) {
  177. return Script::isValidScriptId(id);
  178. }
  179. int ScriptApi::vcpu_mapVarId(int varid, int scriptid) {
  180. return Script::varIdToGlobal(varid, scriptid);
  181. }
  182. int ScriptApi::vcpu_getUserAncestorId(int varid, int scriptid) {
  183. return Script::getUserAncestor(varid, scriptid);
  184. }
  185. int ScriptApi::vcpu_getNumEvents() {
  186. return Script::getNumEventsLinked();
  187. }
  188. int ScriptApi::vcpu_getEvent(int event, int *dlf, int *script, int *var) {
  189. return Script::getLinkedEventParams(event, dlf, script, var);
  190. }
  191. int ScriptApi::vcpu_getComplete() {
  192. return VCPU::getComplete();
  193. }
  194. const char * ScriptApi::vcpu_getClassName(int vcpuid, int localclassid) {
  195. return VCPU::getClassName(vcpuid, localclassid);
  196. }