Simple game engine with complete export to scripting language
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ScriptSystem_Application.cpp 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include "Application.h"
  2. namespace BlueCore
  3. {
  4. static weak_ptr<Application> gApplication;
  5. static SQInteger _quit(HSQUIRRELVM v)
  6. {
  7. if (gApplication.valid())
  8. gApplication->quit();
  9. return 0;
  10. }
  11. static SQInteger _toggle_pause(HSQUIRRELVM v)
  12. {
  13. if (gApplication.valid())
  14. gApplication->togglePause();
  15. return 0;
  16. }
  17. static SQInteger _setscenegraph(HSQUIRRELVM v)
  18. {
  19. SceneGraph *scenegraph = 0;
  20. sq_getinstanceup(v, -1, ( void ** ) &scenegraph, 0);
  21. gApplication->setSceneGraph(scenegraph);
  22. return 0;
  23. }
  24. void setupScriptSystem_Application(ScriptSystem* scriptsystem,
  25. Application* application)
  26. {
  27. if (application == 0)
  28. return;
  29. gApplication = application;
  30. HSQUIRRELVM vm = scriptsystem->getVM();
  31. sq_pushroottable(vm);
  32. sq_pushstring(vm, "quit", -1);
  33. sq_newclosure(vm, _quit, 0);
  34. sq_newslot(vm, -3, false);
  35. sq_pushstring(vm, "togglePause", -1);
  36. sq_newclosure(vm, _toggle_pause, 0);
  37. sq_newslot(vm, -3, false);
  38. sq_pushstring(vm, "setSceneGraph", -1);
  39. sq_newclosure(vm, _setscenegraph, 0);
  40. sq_newslot(vm, -3, false);
  41. sq_pop(vm, 1);
  42. }
  43. }