2
0

lua_environment.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. Copyright (c) 2013 Daniele Bartolini, Michele Rossi
  3. Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
  4. Permission is hereby granted, free of charge, to any person
  5. obtaining a copy of this software and associated documentation
  6. files (the "Software"), to deal in the Software without
  7. restriction, including without limitation the rights to use,
  8. copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the
  10. Software is furnished to do so, subject to the following
  11. conditions:
  12. The above copyright notice and this permission notice shall be
  13. included in all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  16. OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  19. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #pragma once
  24. #include "config.h"
  25. #include "types.h"
  26. #include "macros.h"
  27. #include "math_types.h" // HACK
  28. #include "lua.hpp"
  29. namespace crown
  30. {
  31. enum LuaArgumentType
  32. {
  33. ARGUMENT_FLOAT
  34. };
  35. struct LuaResource;
  36. // HACK
  37. struct Actor;
  38. struct Unit;
  39. /// LuaEnvironment is a wrapper of a subset of Lua functions and
  40. /// provides utilities for extending Lua
  41. struct LuaEnvironment
  42. {
  43. LuaEnvironment(lua_State* L);
  44. void execute(const LuaResource* lr);
  45. /// Loads and executes the given @a s lua string.
  46. void execute_string(const char* s);
  47. /// Loads the function with the given @a name and @a func into the table @a module.
  48. void load_module_function(const char* module, const char* name, const lua_CFunction func);
  49. void load_module_function(const char* module, const char* name, const char* value);
  50. void load_module_constructor(const char* module, const lua_CFunction func);
  51. /// Loads the enum with the given @a name and @a value into the table @a module.
  52. void load_module_enum(const char* module, const char* name, uint32_t value);
  53. /// Calls the global function @a func with @a argc argument number.
  54. /// Each argument is a pair (type, value).
  55. /// Example call:
  56. /// call_global("myfunc", 1, ARGUMENT_FLOAT, 3.14f)
  57. /// Returns true if success, false otherwise
  58. void call_global(const char* func, uint8_t argc, ...);
  59. // HACK
  60. void call_physics_callback(Actor* actor_0, Actor* actor_1, Unit* unit_0, Unit* unit_1, const Vector3& where, const Vector3& normal, const char* type);
  61. void call_trigger_callback(Actor* trigger, Actor* other, const char* type);
  62. private:
  63. lua_State* m_L;
  64. private:
  65. // Disable copying
  66. LuaEnvironment(const LuaEnvironment&);
  67. LuaEnvironment& operator=(const LuaEnvironment&);
  68. };
  69. } // namespace crown