operator_id.hpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright (c) 2003 Daniel Wallin and Arvid Norberg
  2. // Permission is hereby granted, free of charge, to any person obtaining a
  3. // copy of this software and associated documentation files (the "Software"),
  4. // to deal in the Software without restriction, including without limitation
  5. // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  6. // and/or sell copies of the Software, and to permit persons to whom the
  7. // Software is furnished to do so, subject to the following conditions:
  8. // The above copyright notice and this permission notice shall be included
  9. // in all copies or substantial portions of the Software.
  10. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
  11. // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  12. // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  13. // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
  14. // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
  15. // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  16. // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
  18. // OR OTHER DEALINGS IN THE SOFTWARE.
  19. #ifndef LUABIND_OPERATOR_ID_HPP_INCLUDED
  20. #define LUABIND_OPERATOR_ID_HPP_INCLUDED
  21. #include <luabind/config.hpp>
  22. namespace luabind { namespace detail {
  23. enum operator_id
  24. {
  25. op_add = 0,
  26. op_sub,
  27. op_mul,
  28. op_div,
  29. op_pow,
  30. op_lt,
  31. op_le,
  32. op_eq,
  33. op_call,
  34. op_unm,
  35. op_tostring,
  36. op_concat,
  37. op_len,
  38. number_of_operators
  39. };
  40. inline const char* get_operator_name(int i)
  41. {
  42. static const char* a[number_of_operators] = {
  43. "__add", "__sub", "__mul", "__div", "__pow",
  44. "__lt", "__le", "__eq", "__call", "__unm",
  45. "__tostring", "__concat", "__len" };
  46. return a[i];
  47. }
  48. inline const char* get_operator_symbol(int i)
  49. {
  50. static const char* a[number_of_operators] = {
  51. "+", "-", "*", "/", "^", "<",
  52. "<=", "==", "()", "- (unary)",
  53. "tostring", "..", "#" };
  54. return a[i];
  55. }
  56. inline bool is_unary(int i)
  57. {
  58. // the reason why unary minus is not considered a unary operator here is
  59. // that it always is given two parameters, where the second parameter always
  60. // is nil.
  61. return i == op_tostring;
  62. }
  63. }}
  64. #endif // LUABIND_OPERATOR_ID_HPP_INCLUDED