OpenMiner  0.0.1a
Voxel game engine
Classes | Typedefs | Functions | Variables
sol::usertype_detail Namespace Reference

Classes

struct  call_information
 
struct  callable_binding
 
struct  no_comp
 
struct  registrar
 
struct  simple_map
 
struct  variable_wrapper
 

Typedefs

template<typename K , typename V , typename H = std::hash<K>, typename E = std::equal_to<>>
using map_t = std::unordered_map< K, V, H, E >
 
typedef void(* base_walk) (lua_State *, bool &, int &, string_view &)
 
typedef int(* member_search) (lua_State *, void *, usertype_metatable_core &, int)
 
typedef map_t< std::string, call_informationmapping_t
 
typedef map_t< std::string, std::unique_ptr< variable_wrapper > > variable_map
 
typedef map_t< std::string, objectfunction_map
 

Functions

template<typename T , typename Regs , typename Fx >
void insert_default_registrations (Regs &l, int &index, Fx &&fx)
 
template<typename T , typename Regs , meta::enable< meta::neg< std::is_pointer< T >>, std::is_destructible< T >> = meta::enabler>
void make_destructor (Regs &l, int &index)
 
template<typename T >
int is_check (lua_State *L)
 
template<typename T >
int member_default_to_string (std::true_type, lua_State *L)
 
template<typename T >
int member_default_to_string (std::false_type, lua_State *L)
 
template<typename T >
int adl_default_to_string (std::true_type, lua_State *L)
 
template<typename T >
int adl_default_to_string (std::false_type, lua_State *L)
 
template<typename T >
int oss_default_to_string (std::true_type, lua_State *L)
 
template<typename T >
int oss_default_to_string (std::false_type, lua_State *L)
 
template<typename T >
int default_to_string (lua_State *L)
 
template<typename T , typename Op >
int comparsion_operator_wrap (lua_State *L)
 
template<typename T , typename Op , typename Supports , typename Regs , meta::enable< Supports > = meta::enabler>
void make_reg_op (Regs &l, int &index, const char *name)
 
template<typename T , typename Supports , typename Regs , meta::enable< Supports > = meta::enabler>
void make_to_string_op (Regs &l, int &index)
 
template<typename T , typename Regs , meta::enable< meta::has_deducible_signature< T >> = meta::enabler>
void make_call_op (Regs &l, int &index)
 
template<typename T , typename Regs >
void make_length_op_const (std::true_type, Regs &l, int &index)
 
template<typename T , typename Regs >
void make_length_op_const (std::false_type, Regs &l, int &index)
 
template<typename T , typename Regs , meta::enable< meta::has_size< T >, meta::has_size< const T >> = meta::enabler>
void make_length_op (Regs &l, int &index)
 
template<typename T , typename Regs , typename Fx >
void insert_default_registrations (std::false_type, Regs &, int &, Fx &&)
 
template<typename T , typename Regs , typename Fx >
void insert_default_registrations (std::true_type, Regs &l, int &index, Fx &&fx)
 
int is_indexer (string_view s)
 
int is_indexer (meta_function mf)
 
int is_indexer (call_construction)
 
int is_indexer (base_classes_tag)
 
auto make_string_view (string_view s)
 
auto make_string_view (call_construction)
 
auto make_string_view (meta_function mf)
 
auto make_string_view (base_classes_tag)
 
template<typename Arg >
std::string make_string (Arg &&arg)
 
template<typename N >
luaL_Reg make_reg (N &&n, lua_CFunction f)
 
bool is_toplevel (lua_State *L, int index=magic_index)
 
int runtime_object_call (lua_State *L, void *, usertype_metatable_core &umc, int runtimetarget)
 
template<typename T , bool is_index>
int indexing_fail (lua_State *L)
 
int runtime_new_index (lua_State *L, void *, usertype_metatable_core &, int runtimetarget)
 
template<typename T , bool is_simple>
int metatable_new_index (lua_State *L)
 
template<bool is_index, typename Base >
static void walk_single_base (lua_State *L, bool &found, int &ret, string_view &)
 
template<bool is_index, typename... Bases>
static void walk_all_bases (lua_State *L, bool &found, int &ret, string_view &accessor)
 
int call_indexing_object (lua_State *L, object &f)
 
template<typename T , bool is_index, bool toplevel = false, bool has_indexing = false>
int simple_core_indexing_call (lua_State *L)
 
template<typename T , bool has_indexing = false>
int simple_real_index_call (lua_State *L)
 
template<typename T , bool has_indexing = false>
int simple_real_new_index_call (lua_State *L)
 
template<typename T , bool has_indexing = false>
int simple_index_call (lua_State *L)
 
template<typename T , bool has_indexing = false>
int simple_new_index_call (lua_State *L)
 

Variables

const int metatable_index = 2
 
const int metatable_core_index = 3
 
const int filler_index = 4
 
const int magic_index = 5
 
const int simple_metatable_index = 2
 
const int index_function_index = 3
 
const int newindex_function_index = 4
 
const lua_Integer toplevel_magic = static_cast<lua_Integer>(0xCCC2CCC1)
 

Typedef Documentation

§ base_walk

typedef void(* sol::usertype_detail::base_walk) (lua_State *, bool &, int &, string_view &)

§ function_map

§ map_t

template<typename K , typename V , typename H = std::hash<K>, typename E = std::equal_to<>>
using sol::usertype_detail::map_t = typedef std::unordered_map<K, V, H, E>

§ mapping_t

§ member_search

typedef int(* sol::usertype_detail::member_search) (lua_State *, void *, usertype_metatable_core &, int)

§ variable_map

Function Documentation

§ adl_default_to_string() [1/2]

template<typename T >
int sol::usertype_detail::adl_default_to_string ( std::true_type  ,
lua_State *  L 
)
inline
18149  {
18150  using namespace std;
18151  decltype(auto) ts = to_string(stack::get<T>(L, 1));
18152  return stack::push(L, std::forward<decltype(ts)>(ts));
18153  }
stack_proxy get(types< Args... > t, const protected_function_result &fr)
Definition: sol.hpp:12588
int push(lua_State *L, Arg &&arg, Args &&... args)
Definition: sol.hpp:7776

§ adl_default_to_string() [2/2]

template<typename T >
int sol::usertype_detail::adl_default_to_string ( std::false_type  ,
lua_State *  L 
)
inline
18156  {
18157  return member_default_to_string<T>(meta::supports_to_string_member<T>(), L);
18158  }

§ call_indexing_object()

int sol::usertype_detail::call_indexing_object ( lua_State *  L,
object f 
)
inline
19182  {
19183  int before = lua_gettop(L);
19184  f.push();
19185  for (int i = 1; i <= before; ++i) {
19186  lua_pushvalue(L, i);
19187  }
19188  lua_call(L, before, LUA_MULTRET);
19189  int after = lua_gettop(L);
19190  return after - before;
19191  }

§ comparsion_operator_wrap()

template<typename T , typename Op >
int sol::usertype_detail::comparsion_operator_wrap ( lua_State *  L)
18178  {
18179  auto maybel = stack::unqualified_check_get<T&>(L, 1);
18180  if (maybel) {
18181  auto mayber = stack::unqualified_check_get<T&>(L, 2);
18182  if (mayber) {
18183  auto& l = *maybel;
18184  auto& r = *mayber;
18185  if (std::is_same<no_comp, Op>::value) {
18186  return stack::push(L, detail::ptr(l) == detail::ptr(r));
18187  }
18188  else {
18189  Op op;
18190  return stack::push(L, (detail::ptr(l) == detail::ptr(r)) || op(detail::deref(l), detail::deref(r)));
18191  }
18192  }
18193  }
18194  return stack::push(L, false);
18195  }
auto deref(T &&item) -> decltype(std::forward< T >(item))
Definition: sol.hpp:1842
T * ptr(T *val)
Definition: sol.hpp:1872
int push(lua_State *L, Arg &&arg, Args &&... args)
Definition: sol.hpp:7776

§ default_to_string()

template<typename T >
int sol::usertype_detail::default_to_string ( lua_State *  L)
inline
18173  {
18174  return oss_default_to_string<T>(meta::supports_ostream_op<T>(), L);
18175  }

§ indexing_fail()

template<typename T , bool is_index>
int sol::usertype_detail::indexing_fail ( lua_State *  L)
inline
18549  {
18550  if (is_index) {
18551 #if 0 //defined(SOL_SAFE_USERTYPE) && SOL_SAFE_USERTYPE
18552  auto maybeaccessor = stack::get<optional<string_view>>(L, is_index ? -1 : -2);
18553  string_view accessor = maybeaccessor.value_or(string_detail::string_shim("(unknown)"));
18554  return luaL_error(L, "sol: attempt to index (get) nil value \"%s\" on userdata (bad (misspelled?) key name or does not exist)", accessor.data());
18555 #else
18556  if (is_toplevel(L)) {
18557  if (lua_getmetatable(L, 1) == 1) {
18558  int metatarget = lua_gettop(L);
18559  stack::get_field(L, stack_reference(L, raw_index(2)), metatarget);
18560  return 1;
18561  }
18562  }
18563  // With runtime extensibility, we can't hard-error things. They have to return nil, like regular table types, unfortunately...
18564  return stack::push(L, lua_nil);
18565 #endif
18566  }
18567  else {
18568  auto maybeaccessor = stack::get<optional<string_view>>(L, is_index ? -1 : -2);
18569  string_view accessor = maybeaccessor.value_or(string_view("(unknown)"));
18570  return luaL_error(L, "sol: attempt to index (set) nil value \"%s\" on userdata (bad (misspelled?) key name or does not exist)", accessor.data());
18571  }
18572  }
const lua_nil_t lua_nil
Definition: sol.hpp:4683
bool is_toplevel(lua_State *L, int index=magic_index)
Definition: sol.hpp:18536
int push(lua_State *L, Arg &&arg, Args &&... args)
Definition: sol.hpp:7776
basic_string_view< char > string_view
Definition: sol.hpp:1186
void get_field(lua_State *L, Key &&key, int tableindex)
Definition: sol.hpp:8074

§ insert_default_registrations() [1/3]

template<typename T , typename Regs , typename Fx >
void sol::usertype_detail::insert_default_registrations ( Regs &  l,
int &  index,
Fx &&  fx 
)
18327  {
18328  insert_default_registrations<T>(is_automagical<T>(), l, index, std::forward<Fx>(fx));
18329  }

§ insert_default_registrations() [2/3]

template<typename T , typename Regs , typename Fx >
void sol::usertype_detail::insert_default_registrations ( std::false_type  ,
Regs &  ,
int &  ,
Fx &&   
)
18292  {
18293  // no-op
18294  }

§ insert_default_registrations() [3/3]

template<typename T , typename Regs , typename Fx >
void sol::usertype_detail::insert_default_registrations ( std::true_type  ,
Regs &  l,
int &  index,
Fx &&  fx 
)
18297  {
18298  if (fx(meta_function::less_than)) {
18299  const char* name = to_string(meta_function::less_than).c_str();
18300  usertype_detail::make_reg_op<T, std::less<>, meta::supports_op_less<T>>(l, index, name);
18301  }
18302  if (fx(meta_function::less_than_or_equal_to)) {
18303  const char* name = to_string(meta_function::less_than_or_equal_to).c_str();
18304  usertype_detail::make_reg_op<T, std::less_equal<>, meta::supports_op_less_equal<T>>(l, index, name);
18305  }
18306  if (fx(meta_function::equal_to)) {
18307  const char* name = to_string(meta_function::equal_to).c_str();
18308  usertype_detail::make_reg_op<T, std::conditional_t<meta::supports_op_equal<T>::value, std::equal_to<>, usertype_detail::no_comp>, std::true_type>(l, index, name);
18309  }
18310  if (fx(meta_function::pairs)) {
18311  const char* name = to_string(meta_function::pairs).c_str();
18312  l[index] = luaL_Reg{ name, container_usertype_metatable<as_container_t<T>>::pairs_call };
18313  ++index;
18314  }
18315  if (fx(meta_function::length)) {
18316  usertype_detail::make_length_op<T>(l, index);
18317  }
18318  if (fx(meta_function::to_string)) {
18319  usertype_detail::make_to_string_op<T, is_to_stringable<T>>(l, index);
18320  }
18321  if (fx(meta_function::call_function)) {
18322  usertype_detail::make_call_op<T>(l, index);
18323  }
18324  }
const string_view & to_string(error_code ec)
Definition: sol.hpp:8913

§ is_check()

template<typename T >
int sol::usertype_detail::is_check ( lua_State *  L)
18133  {
18134  return stack::push(L, stack::check<T>(L, 1, &no_panic));
18135  }
int no_panic(lua_State *, int, type, type, const char *=nullptr) noexcept
Definition: sol.hpp:6402
int push(lua_State *L, Arg &&arg, Args &&... args)
Definition: sol.hpp:7776

§ is_indexer() [1/4]

int sol::usertype_detail::is_indexer ( string_view  s)
inline
18469  {
18470  if (s == to_string(meta_function::index)) {
18471  return 1;
18472  }
18473  else if (s == to_string(meta_function::new_index)) {
18474  return 2;
18475  }
18476  return 0;
18477  }
const string_view & to_string(error_code ec)
Definition: sol.hpp:8913

§ is_indexer() [2/4]

int sol::usertype_detail::is_indexer ( meta_function  mf)
inline
18479  {
18480  if (mf == meta_function::index) {
18481  return 1;
18482  }
18483  else if (mf == meta_function::new_index) {
18484  return 2;
18485  }
18486  return 0;
18487  }

§ is_indexer() [3/4]

int sol::usertype_detail::is_indexer ( call_construction  )
inline
18489  {
18490  return 0;
18491  }

§ is_indexer() [4/4]

int sol::usertype_detail::is_indexer ( base_classes_tag  )
inline
18493  {
18494  return 0;
18495  }

§ is_toplevel()

bool sol::usertype_detail::is_toplevel ( lua_State *  L,
int  index = magic_index 
)
inline
18536  {
18537  int isnum = 0;
18538  lua_Integer magic = lua_tointegerx(L, upvalue_index(index), &isnum);
18539  return isnum != 0 && magic == toplevel_magic;
18540  }
const lua_Integer toplevel_magic
Definition: sol.hpp:18467

§ make_call_op()

template<typename T , typename Regs , meta::enable< meta::has_deducible_signature< T >> = meta::enabler>
void sol::usertype_detail::make_call_op ( Regs &  l,
int &  index 
)
inline
18223  {
18224  const char* name = to_string(meta_function::call).c_str();
18225  lua_CFunction f = &c_call<decltype(&T::operator()), &T::operator()>;
18226  l[index] = luaL_Reg{ name, f };
18227  ++index;
18228  }
int call(lua_State *L)
Definition: sol.hpp:12872
const string_view & to_string(error_code ec)
Definition: sol.hpp:8913

§ make_destructor()

template<typename T , typename Regs , meta::enable< meta::neg< std::is_pointer< T >>, std::is_destructible< T >> = meta::enabler>
void sol::usertype_detail::make_destructor ( Regs &  l,
int &  index 
)
18272  {
18273  const char* name = to_string(meta_function::garbage_collect).c_str();
18274  l[index] = luaL_Reg{ name, is_unique_usertype<T>::value ? &detail::unique_destruct<T> : &detail::usertype_alloc_destruct<T> };
18275  ++index;
18276  }
const string_view & to_string(error_code ec)
Definition: sol.hpp:8913

§ make_length_op()

template<typename T , typename Regs , meta::enable< meta::has_size< T >, meta::has_size< const T >> = meta::enabler>
void sol::usertype_detail::make_length_op ( Regs &  l,
int &  index 
)
inline
18262  {
18263  make_length_op_const<T>(meta::has_size<const T>(), l, index);
18264  }

§ make_length_op_const() [1/2]

template<typename T , typename Regs >
void sol::usertype_detail::make_length_op_const ( std::true_type  ,
Regs &  l,
int &  index 
)
inline
18236  {
18237  const char* name = to_string(meta_function::length).c_str();
18238 #if defined(__clang__)
18239  l[index] = luaL_Reg{ name, &c_call<decltype(&T::size), &T::size> };
18240 #else
18241  typedef decltype(std::declval<T>().size()) R;
18242  using sz_func = R(T::*)()const;
18243  l[index] = luaL_Reg{ name, &c_call<decltype(static_cast<sz_func>(&T::size)), static_cast<sz_func>(&T::size)> };
18244 #endif
18245  ++index;
18246  }
const string_view & to_string(error_code ec)
Definition: sol.hpp:8913

§ make_length_op_const() [2/2]

template<typename T , typename Regs >
void sol::usertype_detail::make_length_op_const ( std::false_type  ,
Regs &  l,
int &  index 
)
inline
18249  {
18250  const char* name = to_string(meta_function::length).c_str();
18251 #if defined(__clang__)
18252  l[index] = luaL_Reg{ name, &c_call<decltype(&T::size), &T::size> };
18253 #else
18254  typedef decltype(std::declval<T>().size()) R;
18255  using sz_func = R(T::*)();
18256  l[index] = luaL_Reg{ name, &c_call<decltype(static_cast<sz_func>(&T::size)), static_cast<sz_func>(&T::size)> };
18257 #endif
18258  ++index;
18259  }
const string_view & to_string(error_code ec)
Definition: sol.hpp:8913

§ make_reg()

template<typename N >
luaL_Reg sol::usertype_detail::make_reg ( N &&  n,
lua_CFunction  f 
)
inline
18520  {
18521  luaL_Reg l{make_string_view(std::forward<N>(n)).data(), f};
18522  return l;
18523  }
auto make_string_view(base_classes_tag)
Definition: sol.hpp:18509

§ make_reg_op()

template<typename T , typename Op , typename Supports , typename Regs , meta::enable< Supports > = meta::enabler>
void sol::usertype_detail::make_reg_op ( Regs &  l,
int &  index,
const char *  name 
)
inline
18198  {
18199  lua_CFunction f = &comparsion_operator_wrap<T, Op>;
18200  l[index] = luaL_Reg{ name, f };
18201  ++index;
18202  }

§ make_string()

template<typename Arg >
std::string sol::usertype_detail::make_string ( Arg &&  arg)
inline
18514  {
18515  string_view s = make_string_view(arg);
18516  return std::string(s.data(), s.size());
18517  }
auto make_string_view(base_classes_tag)
Definition: sol.hpp:18509
basic_string_view< char > string_view
Definition: sol.hpp:1186

§ make_string_view() [1/4]

auto sol::usertype_detail::make_string_view ( string_view  s)
inline
18497  {
18498  return s;
18499  }

§ make_string_view() [2/4]

auto sol::usertype_detail::make_string_view ( call_construction  )
inline
18501  {
18502  return string_view(to_string(meta_function::call_function));
18503  }
const string_view & to_string(error_code ec)
Definition: sol.hpp:8913
basic_string_view< char > string_view
Definition: sol.hpp:1186

§ make_string_view() [3/4]

auto sol::usertype_detail::make_string_view ( meta_function  mf)
inline
18505  {
18506  return string_view(to_string(mf));
18507  }
const string_view & to_string(error_code ec)
Definition: sol.hpp:8913
basic_string_view< char > string_view
Definition: sol.hpp:1186

§ make_string_view() [4/4]

auto sol::usertype_detail::make_string_view ( base_classes_tag  )
inline
18509  {
18511  }
decltype(auto) base_class_cast_key()
Definition: sol.hpp:6219
basic_string_view< char > string_view
Definition: sol.hpp:1186

§ make_to_string_op()

template<typename T , typename Supports , typename Regs , meta::enable< Supports > = meta::enabler>
void sol::usertype_detail::make_to_string_op ( Regs &  l,
int &  index 
)
inline
18210  {
18211  const char* name = to_string(meta_function::to_string).c_str();
18212  lua_CFunction f = &detail::static_trampoline<&default_to_string<T>>;
18213  l[index] = luaL_Reg{ name, f };
18214  ++index;
18215  }
const string_view & to_string(error_code ec)
Definition: sol.hpp:8913

§ member_default_to_string() [1/2]

template<typename T >
int sol::usertype_detail::member_default_to_string ( std::true_type  ,
lua_State *  L 
)
inline
18138  {
18139  decltype(auto) ts = stack::get<T>(L, 1).to_string();
18140  return stack::push(L, std::forward<decltype(ts)>(ts));
18141  }
stack_proxy get(types< Args... > t, const protected_function_result &fr)
Definition: sol.hpp:12588
const string_view & to_string(error_code ec)
Definition: sol.hpp:8913
int push(lua_State *L, Arg &&arg, Args &&... args)
Definition: sol.hpp:7776

§ member_default_to_string() [2/2]

template<typename T >
int sol::usertype_detail::member_default_to_string ( std::false_type  ,
lua_State *  L 
)
inline
18144  {
18145  return luaL_error(L, "cannot perform to_string on '%s': no 'to_string' overload in namespace, 'to_string' member function, or operator<<(ostream&, ...) present", detail::demangle<T>().data());
18146  }

§ metatable_new_index()

template<typename T , bool is_simple>
int sol::usertype_detail::metatable_new_index ( lua_State *  L)
inline
18577  {
18578  if (is_toplevel(L)) {
18579  auto non_indexable = [&L]() {
18580  if (is_simple) {
18581  simple_map& sm = stack::get<user<simple_map>>(L, upvalue_index(simple_metatable_index));
18582  function_map& functions = sm.functions;
18583  optional<string_view> maybeaccessor = stack::get<optional<string_view>>(L, 2);
18584  if (!maybeaccessor) {
18585  return;
18586  }
18587  string_view& accessor_view = maybeaccessor.value();
18588 #if defined(SOL_UNORDERED_MAP_COMPATIBLE_HASH) && SOL_UNORDERED_MAP_COMPATIBLE_HASH
18589  auto preexistingit = functions.find(accessor_view, string_view_hash(), std::equal_to<string_view>());
18590 #else
18591  std::string accessor(accessor_view.data(), accessor_view.size());
18592  auto preexistingit = functions.find(accessor);
18593 #endif
18594  if (preexistingit == functions.cend()) {
18595 #if defined(SOL_UNORDERED_MAP_COMPATIBLE_HASH) && SOL_UNORDERED_MAP_COMPATIBLE_HASH
18596  std::string accessor(accessor_view.data(), accessor_view.size());
18597 #endif
18598  functions.emplace_hint(preexistingit, std::move(accessor), object(L, 3));
18599  }
18600  else {
18601  preexistingit->second = object(L, 3);
18602  }
18603  return;
18604  }
18605  usertype_metatable_core& umc = stack::get<light<usertype_metatable_core>>(L, upvalue_index(metatable_core_index));
18606  bool mustindex = umc.mustindex;
18607  if (!mustindex)
18608  return;
18609  optional<string_view> maybeaccessor = stack::get<optional<string_view>>(L, 2);
18610  if (!maybeaccessor) {
18611  return;
18612  }
18613  string_view& accessor_view = maybeaccessor.value();
18614  mapping_t& mapping = umc.mapping;
18615  std::vector<object>& runtime = umc.runtime;
18616  int target = static_cast<int>(runtime.size());
18617 #if defined(SOL_UNORDERED_MAP_COMPATIBLE_HASH) && SOL_UNORDERED_MAP_COMPATIBLE_HASH
18618  auto preexistingit = mapping.find(accessor_view, string_view_hash(), std::equal_to<string_view>());
18619 #else
18620  std::string accessor(accessor_view.data(), accessor_view.size());
18621  auto preexistingit = mapping.find(accessor);
18622 #endif
18623  if (preexistingit == mapping.cend()) {
18624 #if defined(SOL_UNORDERED_MAP_COMPATIBLE_HASH) && SOL_UNORDERED_MAP_COMPATIBLE_HASH
18625  std::string accessor(accessor_view.data(), accessor_view.size());
18626 #endif
18627  runtime.emplace_back(L, 3);
18628  mapping.emplace_hint(mapping.cend(), std::move(accessor), call_information(&runtime_object_call, &runtime_new_index, target));
18629  }
18630  else {
18631  target = preexistingit->second.runtime_target;
18632  runtime[target] = object(L, 3);
18633  preexistingit->second = call_information(&runtime_object_call, &runtime_new_index, target);
18634  }
18635  };
18636  non_indexable();
18637  for (std::size_t i = 0; i < 4; lua_settop(L, 3), ++i) {
18638  const char* metakey = nullptr;
18639  switch (i) {
18640  case 0:
18641  metakey = &usertype_traits<T*>::metatable()[0];
18642  luaL_getmetatable(L, metakey);
18643  break;
18644  case 1:
18645  metakey = &usertype_traits<detail::unique_usertype<T>>::metatable()[0];
18646  luaL_getmetatable(L, metakey);
18647  break;
18648  case 2:
18649  metakey = &usertype_traits<T>::metatable()[0];
18650  luaL_getmetatable(L, metakey);
18651  break;
18652  case 3:
18653  default:
18654  metakey = &usertype_traits<T>::user_metatable()[0];
18655  {
18656  luaL_getmetatable(L, metakey);
18657  lua_getmetatable(L, -1);
18658  }
18659  break;
18660  }
18661  int tableindex = lua_gettop(L);
18662  if (type_of(L, tableindex) == type::lua_nil) {
18663  continue;
18664  }
18665  stack::set_field<false, true>(L, stack_reference(L, raw_index(2)), stack_reference(L, raw_index(3)), tableindex);
18666  }
18667  lua_settop(L, 0);
18668  return 0;
18669  }
18670  return indexing_fail<T, false>(L);
18671  }
std::hash< string_view > string_view_hash
Definition: sol.hpp:1190
int runtime_object_call(lua_State *L, void *, usertype_metatable_core &umc, int runtimetarget)
Definition: sol.hpp:18542
const lua_nil_t lua_nil
Definition: sol.hpp:4683
const int metatable_core_index
Definition: sol.hpp:18381
basic_object< reference > object
Definition: sol.hpp:350
bool is_toplevel(lua_State *L, int index=magic_index)
Definition: sol.hpp:18536
map_t< std::string, call_information > mapping_t
Definition: sol.hpp:18405
const int simple_metatable_index
Definition: sol.hpp:18385
type type_of()
Definition: sol.hpp:5770
map_t< std::string, object > function_map
Definition: sol.hpp:18432
basic_string_view< char > string_view
Definition: sol.hpp:1186
int runtime_new_index(lua_State *L, void *, usertype_metatable_core &, int runtimetarget)
Definition: sol.hpp:18673

§ oss_default_to_string() [1/2]

template<typename T >
int sol::usertype_detail::oss_default_to_string ( std::true_type  ,
lua_State *  L 
)
inline
18161  {
18162  std::ostringstream oss;
18163  oss << stack::unqualified_get<T>(L, 1);
18164  return stack::push(L, oss.str());
18165  }
int push(lua_State *L, Arg &&arg, Args &&... args)
Definition: sol.hpp:7776

§ oss_default_to_string() [2/2]

template<typename T >
int sol::usertype_detail::oss_default_to_string ( std::false_type  ,
lua_State *  L 
)
inline
18168  {
18169  return adl_default_to_string<T>(meta::supports_adl_to_string<T>(), L);
18170  }

§ runtime_new_index()

int sol::usertype_detail::runtime_new_index ( lua_State *  L,
void *  ,
usertype_metatable_core umc,
int  runtimetarget 
)
inline
18673  {
18674  std::vector<object>& runtime = umc.runtime;
18675  object& runtimeobj = runtime[runtimetarget];
18676  runtimeobj = object(L, 3);
18677  return 0;
18678  }
basic_object< reference > object
Definition: sol.hpp:350

§ runtime_object_call()

int sol::usertype_detail::runtime_object_call ( lua_State *  L,
void *  ,
usertype_metatable_core umc,
int  runtimetarget 
)
inline
18542  {
18543  std::vector<object>& runtime = umc.runtime;
18544  object& runtimeobj = runtime[runtimetarget];
18545  return stack::push(L, runtimeobj);
18546  }
int push(lua_State *L, Arg &&arg, Args &&... args)
Definition: sol.hpp:7776

§ simple_core_indexing_call()

template<typename T , bool is_index, bool toplevel = false, bool has_indexing = false>
int sol::usertype_detail::simple_core_indexing_call ( lua_State *  L)
inline
19194  {
19195  simple_map& sm = toplevel
19196  ? stack::get<user<simple_map>>(L, upvalue_index(simple_metatable_index))
19197  : stack::pop<user<simple_map>>(L);
19198  variable_map& variables = sm.variables;
19199  function_map& functions = sm.functions;
19200  static const int keyidx = -2 + static_cast<int>(is_index);
19201  if (toplevel) {
19202  if (type_of(L, keyidx) != type::string) {
19203  if (has_indexing) {
19204  object& indexingfunc = is_index
19205  ? sm.index
19206  : sm.newindex;
19207  return call_indexing_object(L, indexingfunc);
19208  }
19209  else {
19210  return is_index
19211  ? indexing_fail<T, is_index>(L)
19212  : metatable_new_index<T, true>(L);
19213  }
19214  }
19215  }
19216  string_view accessor = stack::get<string_view>(L, keyidx);
19217  variable_wrapper* varwrap = nullptr;
19218  {
19219 #if defined(SOL_UNORDERED_MAP_COMPATIBLE_HASH) && SOL_UNORDERED_MAP_COMPATIBLE_HASH
19220  string_view& accessorkey = accessor;
19221  auto vit = variables.find(accessorkey, string_view_hash(), std::equal_to<string_view>());
19222 #else
19223  std::string accessorkey(accessor.data(), accessor.size());
19224  auto vit = variables.find(accessorkey);
19225 #endif // Compatible Hash
19226  if (vit != variables.cend()) {
19227  varwrap = vit->second.get();
19228  }
19229  }
19230  if (varwrap != nullptr) {
19231  return is_index ? varwrap->index(L) : varwrap->new_index(L);
19232  }
19233  bool function_failed = false;
19234  {
19235 #if defined(SOL_UNORDERED_MAP_COMPATIBLE_HASH) && SOL_UNORDERED_MAP_COMPATIBLE_HASH
19236  string_view& accessorkey = accessor;
19237  auto fit = functions.find(accessorkey, string_view_hash(), std::equal_to<string_view>());
19238 #else
19239  std::string accessorkey(accessor.data(), accessor.size());
19240  auto fit = functions.find(accessorkey);
19241 #endif // Compatible Hash
19242  if (fit != functions.cend()) {
19243  object& func = fit->second;
19244  if (is_index) {
19245  return stack::push(L, func);
19246  }
19247  else {
19248  function_failed = true;
19249  }
19250  }
19251  }
19252  if (function_failed) {
19253  if (has_indexing && !is_toplevel(L)) {
19254  object& indexingfunc = is_index
19255  ? sm.index
19256  : sm.newindex;
19257  return call_indexing_object(L, indexingfunc);
19258  }
19259  else {
19260  return is_index
19261  ? indexing_fail<T, is_index>(L)
19262  : metatable_new_index<T, true>(L);
19263  }
19264  }
19265  /* Check table storage first for a method that works
19266  luaL_getmetatable(L, sm.metakey);
19267  if (type_of(L, -1) != type::lua_nil) {
19268  stack::get_field<false, true>(L, accessor.c_str(), lua_gettop(L));
19269  if (type_of(L, -1) != type::lua_nil) {
19270  // Woo, we found it?
19271  lua_remove(L, -2);
19272  return 1;
19273  }
19274  lua_pop(L, 1);
19275  }
19276  lua_pop(L, 1);
19277  */
19278 
19279  int ret = 0;
19280  bool found = false;
19281  // Otherwise, we need to do propagating calls through the bases
19282  if (is_index) {
19283  sm.indexbaseclasspropogation(L, found, ret, accessor);
19284  }
19285  else {
19286  sm.newindexbaseclasspropogation(L, found, ret, accessor);
19287  }
19288  if (found) {
19289  return ret;
19290  }
19291  if (toplevel) {
19292  if (has_indexing && !is_toplevel(L)) {
19293  object& indexingfunc = is_index
19294  ? sm.index
19295  : sm.newindex;
19296  return call_indexing_object(L, indexingfunc);
19297  }
19298  else {
19299  return is_index
19300  ? indexing_fail<T, is_index>(L)
19301  : metatable_new_index<T, true>(L);
19302  }
19303  }
19304  return -1;
19305  }
std::hash< string_view > string_view_hash
Definition: sol.hpp:1190
bool is_toplevel(lua_State *L, int index=magic_index)
Definition: sol.hpp:18536
int call_indexing_object(lua_State *L, object &f)
Definition: sol.hpp:19182
const int simple_metatable_index
Definition: sol.hpp:18385
type type_of()
Definition: sol.hpp:5770
decltype(auto) pop(lua_State *L)
Definition: sol.hpp:8064
map_t< std::string, object > function_map
Definition: sol.hpp:18432
int push(lua_State *L, Arg &&arg, Args &&... args)
Definition: sol.hpp:7776
basic_string_view< char > string_view
Definition: sol.hpp:1186
map_t< std::string, std::unique_ptr< variable_wrapper > > variable_map
Definition: sol.hpp:18431

§ simple_index_call()

template<typename T , bool has_indexing = false>
int sol::usertype_detail::simple_index_call ( lua_State *  L)
inline
19318  {
19319 #if defined(__clang__)
19320  return detail::trampoline(L, &simple_real_index_call<T, has_indexing>);
19321 #else
19322  return detail::typed_static_trampoline<decltype(&simple_real_index_call<T, has_indexing>), (&simple_real_index_call<T, has_indexing>)>(L);
19323 #endif
19324  }
int trampoline(lua_State *L, Fx &&f, Args &&... args)
Definition: sol.hpp:5946

§ simple_new_index_call()

template<typename T , bool has_indexing = false>
int sol::usertype_detail::simple_new_index_call ( lua_State *  L)
inline
19327  {
19328 #if defined(__clang__)
19329  return detail::trampoline(L, &simple_real_new_index_call<T, has_indexing>);
19330 #else
19331  return detail::typed_static_trampoline<decltype(&simple_real_new_index_call<T, has_indexing>), (&simple_real_new_index_call<T, has_indexing>)>(L);
19332 #endif
19333  }
int trampoline(lua_State *L, Fx &&f, Args &&... args)
Definition: sol.hpp:5946

§ simple_real_index_call()

template<typename T , bool has_indexing = false>
int sol::usertype_detail::simple_real_index_call ( lua_State *  L)
inline
19308  {
19309  return simple_core_indexing_call<T, true, true, has_indexing>(L);
19310  }

§ simple_real_new_index_call()

template<typename T , bool has_indexing = false>
int sol::usertype_detail::simple_real_new_index_call ( lua_State *  L)
inline
19313  {
19314  return simple_core_indexing_call<T, false, true, has_indexing>(L);
19315  }

§ walk_all_bases()

template<bool is_index, typename... Bases>
static void sol::usertype_detail::walk_all_bases ( lua_State *  L,
bool &  found,
int &  ret,
string_view accessor 
)
static
18711  {
18712  (void)L;
18713  (void)found;
18714  (void)ret;
18715  (void)accessor;
18716  (void)detail::swallow{0, (walk_single_base<is_index, Bases>(L, found, ret, accessor), 0)...};
18717  }
std::initializer_list< int > swallow
Definition: sol.hpp:462

§ walk_single_base()

template<bool is_index, typename Base >
static void sol::usertype_detail::walk_single_base ( lua_State *  L,
bool &  found,
int &  ret,
string_view  
)
static
18681  {
18682  if (found)
18683  return;
18684  const char* metakey = &usertype_traits<Base>::metatable()[0];
18685  const char* gcmetakey = &usertype_traits<Base>::gc_table()[0];
18686  const char* basewalkkey = is_index ? detail::base_class_index_propogation_key() : detail::base_class_new_index_propogation_key();
18687 
18688  luaL_getmetatable(L, metakey);
18689  if (type_of(L, -1) == type::lua_nil) {
18690  lua_pop(L, 1);
18691  return;
18692  }
18693 
18694  stack::get_field(L, basewalkkey);
18695  if (type_of(L, -1) == type::lua_nil) {
18696  lua_pop(L, 2);
18697  return;
18698  }
18699  lua_CFunction basewalkfunc = stack::pop<lua_CFunction>(L);
18700  lua_pop(L, 1);
18701 
18702  stack::get_field<true>(L, gcmetakey);
18703  int value = basewalkfunc(L);
18704  if (value > -1) {
18705  found = true;
18706  ret = value;
18707  }
18708  }
const lua_nil_t lua_nil
Definition: sol.hpp:4683
decltype(auto) base_class_new_index_propogation_key()
Definition: sol.hpp:6229
decltype(auto) base_class_index_propogation_key()
Definition: sol.hpp:6224
type type_of()
Definition: sol.hpp:5770
void get_field(lua_State *L, Key &&key, int tableindex)
Definition: sol.hpp:8074

Variable Documentation

§ filler_index

const int sol::usertype_detail::filler_index = 4

§ index_function_index

const int sol::usertype_detail::index_function_index = 3

§ magic_index

const int sol::usertype_detail::magic_index = 5

§ metatable_core_index

const int sol::usertype_detail::metatable_core_index = 3

§ metatable_index

const int sol::usertype_detail::metatable_index = 2

§ newindex_function_index

const int sol::usertype_detail::newindex_function_index = 4

§ simple_metatable_index

const int sol::usertype_detail::simple_metatable_index = 2

§ toplevel_magic

const lua_Integer sol::usertype_detail::toplevel_magic = static_cast<lua_Integer>(0xCCC2CCC1)