luaruntime.swg 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* -----------------------------------------------------------------------------
  2. * luaruntime.swg
  3. *
  4. * all the runtime code for .
  5. * ----------------------------------------------------------------------------- */
  6. %runtime "swigrun.swg"; /* Common C API type-checking code */
  7. %runtime "luarun.swg"; /* Lua runtime stuff */
  8. %insert(initbeforefunc) "swiginit.swg"
  9. %insert(initbeforefunc) %{
  10. /* Forward declaration of where the user's %init{} gets inserted */
  11. void SWIG_init_user(lua_State* L );
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. /* this is the initialization function
  16. added at the very end of the code
  17. the function is always called SWIG_init, but an earlier #define will rename it
  18. */
  19. #if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
  20. LUALIB_API int SWIG_init(lua_State* L)
  21. #else
  22. SWIGEXPORT int SWIG_init(lua_State* L) /* default Lua action */
  23. #endif
  24. {
  25. #if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC) /* valid for both Lua and eLua */
  26. int i;
  27. int globalRegister = 0;
  28. /* start with global table */
  29. lua_pushglobaltable (L);
  30. /* SWIG's internal initialisation */
  31. SWIG_InitializeModule((void*)L);
  32. SWIG_PropagateClientData();
  33. #endif
  34. #if ((SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUA) && (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC)) || defined(SWIG_LUA_ELUA_EMULATE)
  35. /* add a global fn */
  36. SWIG_Lua_add_function(L,"swig_type",SWIG_Lua_type);
  37. SWIG_Lua_add_function(L,"swig_equals",SWIG_Lua_class_equal);
  38. #endif
  39. #if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC)
  40. /* set up base class pointers (the hierarchy) */
  41. for (i = 0; swig_types[i]; i++){
  42. if (swig_types[i]->clientdata){
  43. SWIG_Lua_init_base_class(L,(swig_lua_class*)(swig_types[i]->clientdata));
  44. }
  45. }
  46. #ifdef SWIG_LUA_MODULE_GLOBAL
  47. globalRegister = 1;
  48. #endif
  49. #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA)
  50. SWIG_Lua_namespace_register(L,&swig_SwigModule, globalRegister);
  51. #endif
  52. #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)
  53. for (i = 0; swig_types[i]; i++){
  54. if (swig_types[i]->clientdata){
  55. SWIG_Lua_elua_class_register_instance(L,(swig_lua_class*)(swig_types[i]->clientdata));
  56. }
  57. }
  58. #endif
  59. #if defined(SWIG_LUA_ELUA_EMULATE)
  60. lua_newtable(L);
  61. SWIG_Lua_elua_emulate_register(L,swig_SwigModule.ns_methods);
  62. SWIG_Lua_elua_emulate_register_clear(L);
  63. if(globalRegister) {
  64. lua_pushstring(L,swig_SwigModule.name);
  65. lua_pushvalue(L,-2);
  66. lua_rawset(L,-4);
  67. }
  68. #endif
  69. #endif
  70. #if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC)
  71. /* invoke user-specific initialization */
  72. SWIG_init_user(L);
  73. /* end module */
  74. /* Note: We do not clean up the stack here (Lua will do this for us). At this
  75. point, we have the globals table and out module table on the stack. Returning
  76. one value makes the module table the result of the require command. */
  77. return 1;
  78. #else
  79. return 0;
  80. #endif
  81. }
  82. #ifdef __cplusplus
  83. }
  84. #endif
  85. %}
  86. /* Note: the initialization function is closed after all code is generated */