lua_environment.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright (c) 2012-2014 Daniele Bartolini and individual contributors.
  3. * License: https://github.com/taylor001/crown/blob/master/LICENSE
  4. */
  5. #pragma once
  6. #include "config.h"
  7. #include "types.h"
  8. #include "macros.h"
  9. #include "resource_types.h"
  10. #include "math_types.h" // HACK
  11. #include "lua.hpp"
  12. namespace crown
  13. {
  14. enum LuaArgumentType
  15. {
  16. ARGUMENT_FLOAT
  17. };
  18. // HACK
  19. struct Actor;
  20. struct Unit;
  21. /// LuaEnvironment is a wrapper of a subset of Lua functions and
  22. /// provides utilities for extending Lua
  23. struct LuaEnvironment
  24. {
  25. LuaEnvironment(lua_State* L);
  26. void execute(const LuaResource* lr);
  27. /// Loads and executes the given @a s lua string.
  28. void execute_string(const char* s);
  29. /// Loads the function with the given @a name and @a func into the table @a module.
  30. void load_module_function(const char* module, const char* name, const lua_CFunction func);
  31. void load_module_function(const char* module, const char* name, const char* value);
  32. void load_module_constructor(const char* module, const lua_CFunction func);
  33. /// Loads the enum with the given @a name and @a value into the table @a module.
  34. void load_module_enum(const char* module, const char* name, uint32_t value);
  35. /// Calls the global function @a func with @a argc argument number.
  36. /// Each argument is a pair (type, value).
  37. /// Example call:
  38. /// call_global("myfunc", 1, ARGUMENT_FLOAT, 3.14f)
  39. /// Returns true if success, false otherwise
  40. void call_global(const char* func, uint8_t argc, ...);
  41. // HACK
  42. 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);
  43. void call_trigger_callback(Actor* trigger, Actor* other, const char* type);
  44. private:
  45. lua_State* _L;
  46. private:
  47. // Disable copying
  48. LuaEnvironment(const LuaEnvironment&);
  49. LuaEnvironment& operator=(const LuaEnvironment&);
  50. };
  51. } // namespace crown