wrapper_base.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. #define LUABIND_BUILDING
  20. #include <luabind/config.hpp>
  21. #include <luabind/lua_include.hpp>
  22. #include <luabind/function.hpp>
  23. #include <luabind/detail/object_rep.hpp>
  24. #include <luabind/detail/class_rep.hpp>
  25. #include <luabind/detail/stack_utils.hpp>
  26. namespace luabind { namespace detail
  27. {
  28. LUABIND_API void do_call_member_selection(lua_State* L, char const* name)
  29. {
  30. object_rep* obj = static_cast<object_rep*>(lua_touserdata(L, -1));
  31. lua_pushstring(L, name);
  32. lua_gettable(L, -2);
  33. lua_replace(L, -2);
  34. if (!is_luabind_function(L, -1))
  35. return;
  36. // this (usually) means the function has not been
  37. // overridden by lua, call the default implementation
  38. lua_pop(L, 1);
  39. obj->crep()->get_default_table(L); // push the crep table
  40. lua_pushstring(L, name);
  41. lua_gettable(L, -2);
  42. lua_remove(L, -2); // remove the crep table
  43. }
  44. }}