Heavily improved benchmark and first set of optimizations to sol/table.hpp, providing much lower access times for calling a function.

This commit is contained in:
ThePhD 2016-01-08 16:16:06 -05:00
parent f4b31c951c
commit 9ff968a09b
11 changed files with 1194 additions and 210 deletions

433
Results - Debug.html Normal file

File diff suppressed because one or more lines are too long

433
Results - Release.html Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,60 @@
#define NONIUS_RUNNER
#include "nonius/nonius.h++"
#include "sol.hpp"
NONIUS_BENCHMARK( "Function Calls", []() {
struct sol_function_result_bench {
void operator () ( nonius::chronometer meter ) const {
sol::state lua;
lua.script( R"(
function r ()
return 1 + 1
end
)" );
sol::function r = lua[ "r" ];
meter.measure( [ & ] ( int run_index ) {
// Measure cost of lua calling and returning a function
return r( );
} );
}
};
struct sol_direct_bench {
void operator () ( nonius::chronometer meter ) const {
sol::state lua;
lua.script( R"(
function r ()
return 1 + 1
end
)" );
auto fun = [ & ] ( int run_index ) {
// Measure cost of lua calling and returning a function
sol::function r = lua[ "r" ];
return r.call<int>( );
};
meter.measure( fun );
}
};
struct c_direct_bench {
void operator () ( nonius::chronometer meter ) const {
sol::state lua;
lua.script( R"(
function r ()
return 1 + 1
end
)" );
lua_State* L = lua.lua_state( );
meter.measure( [ & ] ( int run_index ) {
lua_getglobal( L, "r" );
lua_call( L, 0, 1 );
int lua_out = (int)lua_tonumber( L, -1 );
lua_pop( L, 1 );
return lua_out;
} );
}
};
NONIUS_BENCHMARK( "sol - function_result", sol_function_result_bench() );
NONIUS_BENCHMARK( "sol - int", sol_direct_bench() );
NONIUS_BENCHMARK( "C - int", c_direct_bench( ) );

View File

@ -128,40 +128,40 @@ private:
int stack;
handler(const reference& target) : target(target), stack(0) {
if (target.valid()) {
stack = lua_gettop(target.state()) + 1;
stack = lua_gettop(target.lua_state()) + 1;
target.push();
}
}
~handler() {
if (stack > 0) {
lua_remove(target.state(), stack);
lua_remove(target.lua_state(), stack);
}
}
};
int luacodecall(std::ptrdiff_t argcount, std::ptrdiff_t resultcount, handler& h) const {
return lua_pcallk(state(), static_cast<int>(argcount), static_cast<int>(resultcount), h.stack, 0, nullptr);
return lua_pcallk(lua_state(), static_cast<int>(argcount), static_cast<int>(resultcount), h.stack, 0, nullptr);
}
void luacall(std::ptrdiff_t argcount, std::ptrdiff_t resultcount, handler& h) const {
lua_callk(state(), static_cast<int>(argcount), static_cast<int>(resultcount), 0, nullptr);
lua_callk(lua_state(), static_cast<int>(argcount), static_cast<int>(resultcount), 0, nullptr);
}
template<std::size_t... I, typename... Ret>
std::tuple<Ret...> invoke(indices<I...>, types<Ret...>, std::ptrdiff_t n, handler& h) const {
luacall(n, sizeof...(Ret), h);
const int nreturns = static_cast<int>(sizeof...(Ret));
const int stacksize = lua_gettop(state());
const int stacksize = lua_gettop(lua_state());
const int firstreturn = std::max(0, stacksize - nreturns) + 1;
auto r = std::make_tuple(stack::get<Ret>(state(), firstreturn + I)...);
lua_pop(state(), nreturns);
auto r = std::make_tuple(stack::get<Ret>(lua_state(), firstreturn + I)...);
lua_pop(lua_state(), nreturns);
return r;
}
template<std::size_t I, typename Ret>
Ret invoke(indices<I>, types<Ret>, std::ptrdiff_t n, handler& h) const {
luacall(n, 1, h);
return stack::pop<Ret>(state());
return stack::pop<Ret>(lua_state());
}
template <std::size_t I>
@ -171,7 +171,7 @@ private:
function_result invoke(indices<>, types<>, std::ptrdiff_t n, handler& h) const {
const bool handlerpushed = error_handler.valid();
const int stacksize = lua_gettop(state());
const int stacksize = lua_gettop(lua_state());
const int firstreturn = std::max(0, stacksize - static_cast<int>(n) - 1);
int code = LUA_OK;
try {
@ -181,27 +181,27 @@ private:
catch (const std::exception& error) {
code = LUA_ERRRUN;
h.stack = 0;
stack::push(state(), error.what());
stack::push(lua_state(), error.what());
}
// TODO: handle idiots?
/*catch (const char* error) {
code = LUA_ERRRUN;
stack::push(state(), error);
stack::push(lua_state(), error);
}
catch (const std::string& error) {
code = LUA_ERRRUN;
stack::push(state(), error);
stack::push(lua_state(), error);
}
catch (...) {
code = LUA_ERRRUN;
stack::push( state(), "[sol] an unknownable runtime exception occurred" );
stack::push( lua_state(), "[sol] an unknownable runtime exception occurred" );
}*/
catch (...) {
throw;
}
const int poststacksize = lua_gettop(state());
const int poststacksize = lua_gettop(lua_state());
const int returncount = poststacksize - firstreturn;
return function_result(state(), firstreturn + ( handlerpushed ? 0 : 1 ), returncount, static_cast<call_error>(code));
return function_result(lua_state(), firstreturn + ( handlerpushed ? 0 : 1 ), returncount, static_cast<call_error>(code));
}
public:
@ -232,7 +232,7 @@ public:
-> decltype(invoke(types<Ret...>(), types<Ret...>(), 0, std::declval<handler&>())) {
handler h(error_handler);
push();
int pushcount = stack::push_args(state(), std::forward<Args>(args)...);
int pushcount = stack::push_args(lua_state(), std::forward<Args>(args)...);
auto tr = types<Ret...>();
return invoke(tr, tr, pushcount, h);
}

View File

@ -33,14 +33,14 @@ public:
object() = default;
template<typename T>
auto as() const -> decltype(stack::get<T>(state())) const {
auto as() const -> decltype(stack::get<T>(lua_state())) const {
push();
type actual = stack::get<type>(state());
type actual = stack::get<type>(lua_state());
// This code is actually present
// in almost all of the type-getters,
// and it thus insanely redundant
// type_assert(state(), -1, type_of<T>(), actual);
return stack::pop<T>(state());
// type_assert(lua_state(), -1, type_of<T>(), actual);
return stack::pop<T>(lua_state());
}
template<typename T>

View File

@ -97,7 +97,7 @@ public:
return static_cast<type>(result);
}
lua_State* state() const noexcept {
lua_State* lua_state() const noexcept {
return L;
}
};

View File

@ -30,7 +30,7 @@ namespace sol {
namespace detail {
inline int atpanic(lua_State* L) {
const char* message = lua_tostring(L, -1);
std::string err = message ? message : "An unexpected error occured and forced the lua state to call atpanic";
std::string err = message ? message : "An unexpected error occurred and forced the lua state to call atpanic";
throw error(err);
}
} // detail
@ -53,18 +53,12 @@ class state {
private:
std::unique_ptr<lua_State, void(*)(lua_State*)> L;
table reg;
table global;
global_table globals;
public:
state(lua_CFunction panic = detail::atpanic):
L(luaL_newstate(), lua_close),
reg(L.get(), LUA_REGISTRYINDEX),
#if SOL_LUA_VERSION < 502
// Global table is just a special index
global(L.get(), LUA_GLOBALSINDEX) {
#else
// Global tables are stored in the environment/registry table
global(reg.get<table>(LUA_RIDX_GLOBALS)) {
#endif // Lua 5.2
globals(detail::global_overload, reg) {
set_panic(panic);
}
@ -152,13 +146,13 @@ public:
template<typename... Args, typename... Keys>
auto get(Keys&&... keys) const
-> decltype(global.get<Args...>(std::forward<Keys>(keys)...)) {
return global.get<Args...>(std::forward<Keys>(keys)...);
-> decltype(globals.get<Args...>(std::forward<Keys>(keys)...)) {
return globals.get<Args...>(std::forward<Keys>(keys)...);
}
template<typename T, typename U>
state& set(T&& key, U&& value) {
global.set(std::forward<T>(key), std::forward<U>(value));
globals.set(std::forward<T>(key), std::forward<U>(value));
return *this;
}
@ -189,7 +183,7 @@ public:
template<typename Key, typename T>
state& set_usertype(Key&& key, usertype<T>& user) {
global.set_usertype(std::forward<Key>(key), user);
globals.set_usertype(std::forward<Key>(key), user);
return *this;
}
@ -208,7 +202,7 @@ public:
template <typename Fx>
void for_each(Fx&& fx) {
global.for_each(std::forward<Fx>(fx));
globals.for_each(std::forward<Fx>(fx));
}
template<typename T>
@ -216,7 +210,7 @@ public:
lua_createtable(L.get(), narr, nrec);
table result(L.get());
lua_pop(L.get(), 1);
global.set(std::forward<T>(key), result);
globals.set(std::forward<T>(key), result);
return result;
}
@ -227,8 +221,8 @@ public:
return result;
}
table global_table() const {
return global;
global_table global() const {
return globals;
}
table registry() const {
@ -240,42 +234,42 @@ public:
}
template<typename T>
proxy<table, T> operator[](T&& key) {
return global[std::forward<T>(key)];
proxy<global_table, T> operator[](T&& key) {
return globals[std::forward<T>(key)];
}
template<typename T>
proxy<const table, T> operator[](T&& key) const {
return global[std::forward<T>(key)];
proxy<const global_table, T> operator[](T&& key) const {
return globals[std::forward<T>(key)];
}
template<typename... Args, typename R, typename Key>
state& set_function(Key&& key, R fun_ptr(Args...)){
global.set_function(std::forward<Key>(key), fun_ptr);
globals.set_function(std::forward<Key>(key), fun_ptr);
return *this;
}
template<typename Sig, typename Key>
state& set_function(Key&& key, Sig* fun_ptr){
global.set_function(std::forward<Key>(key), fun_ptr);
globals.set_function(std::forward<Key>(key), fun_ptr);
return *this;
}
template<typename... Args, typename R, typename C, typename T, typename Key>
state& set_function(Key&& key, R (C::*mem_ptr)(Args...), T&& obj) {
global.set_function(std::forward<Key>(key), mem_ptr, std::forward<T>(obj));
globals.set_function(std::forward<Key>(key), mem_ptr, std::forward<T>(obj));
return *this;
}
template<typename Sig, typename C, typename T, typename Key>
state& set_function(Key&& key, Sig C::* mem_ptr, T&& obj) {
global.set_function(std::forward<Key>(key), mem_ptr, std::forward<T>(obj));
globals.set_function(std::forward<Key>(key), mem_ptr, std::forward<T>(obj));
return *this;
}
template<typename... Sig, typename Fx, typename Key>
state& set_function(Key&& key, Fx&& fx) {
global.set_function<Sig...>(std::forward<Key>(key), std::forward<Fx>(fx));
globals.set_function<Sig...>(std::forward<Key>(key), std::forward<Fx>(fx));
return *this;
}
};

View File

@ -22,167 +22,10 @@
#ifndef SOL_TABLE_HPP
#define SOL_TABLE_HPP
#include "proxy.hpp"
#include "stack.hpp"
#include "function_types.hpp"
#include "usertype.hpp"
#include "table_core.hpp"
namespace sol {
class table : public reference {
friend class state;
template<typename T, typename Key>
stack::get_return<T> single_get(Key&& key) const {
push();
stack::push(state(), std::forward<Key>(key));
lua_gettable(state(), -2);
stack::get_return<T> result = stack::pop<T>(state());
pop();
return result;
}
template<typename Keys, typename... Ret, std::size_t... I>
stack::get_return<Ret...> tuple_get(types<Ret...>, indices<I...>, Keys&& keys) const {
return stack::get_return<Ret...>(single_get<Ret>(std::get<I>(keys))...);
}
template<typename Keys, typename Ret, std::size_t I>
stack::get_return<Ret> tuple_get(types<Ret>, indices<I>, Keys&& keys) const {
return single_get<Ret>(std::get<I>(keys));
}
public:
table() noexcept : reference() {}
table(lua_State* L, int index = -1) : reference(L, index) {
type_assert(L, index, type::table);
}
template<typename... Ret, typename... Keys>
stack::get_return<Ret...> get( Keys&&... keys ) const {
return tuple_get(types<Ret...>(), build_indices<sizeof...(Ret)>(), std::tie(keys...));
}
template<typename T, typename U>
table& set(T&& key, U&& value) {
push();
stack::push(state(), std::forward<T>(key));
stack::push(state(), std::forward<U>(value));
lua_settable(state(), -3);
lua_pop(state(), 1);
return *this;
}
template<typename T>
SOL_DEPRECATED table& set_userdata(usertype<T>& user) {
return set_usertype(user);
}
template<typename Key, typename T>
SOL_DEPRECATED table& set_userdata(Key&& key, usertype<T>& user) {
return set_usertype(std::forward<Key>(key), user);
}
template<typename T>
table& set_usertype(usertype<T>& user) {
return set_usertype(usertype_traits<T>::name, user);
}
template<typename Key, typename T>
table& set_usertype(Key&& key, usertype<T>& user) {
push();
stack::push(state(), std::forward<Key>(key));
stack::push(state(), user);
lua_settable(state(), -3);
lua_pop(state(), 1);
return *this;
}
template<typename Fx>
void for_each(Fx&& fx) const {
push();
stack::push(state(), nil);
while (lua_next(this->state(), -2)) {
sol::object key(state(), -2);
sol::object value(state(), -1);
fx(key, value);
lua_pop(state(), 1);
}
pop();
}
size_t size() const {
push();
size_t result = lua_rawlen(state(), -1);
pop();
return result;
}
template<typename T>
proxy<table, T> operator[]( T&& key ) {
return proxy<table, T>( *this, std::forward<T>( key ) );
}
template<typename T>
proxy<const table, T> operator[]( T&& key ) const {
return proxy<const table, T>( *this, std::forward<T>( key ) );
}
void pop(int n = 1) const noexcept {
lua_pop(state(), n);
}
template<typename... Args, typename R, typename Key>
table& set_function(Key&& key, R fun_ptr(Args...)){
set_resolved_function(std::forward<Key>(key), fun_ptr);
return *this;
}
template<typename Sig, typename Key>
table& set_function(Key&& key, Sig* fun_ptr){
set_resolved_function(std::forward<Key>(key), fun_ptr);
return *this;
}
template<typename... Args, typename R, typename C, typename T, typename Key>
table& set_function(Key&& key, R (C::*mem_ptr)(Args...), T&& obj) {
set_resolved_function(std::forward<Key>(key), mem_ptr, std::forward<T>(obj));
return *this;
}
template<typename Sig, typename C, typename T, typename Key>
table& set_function(Key&& key, Sig C::* mem_ptr, T&& obj) {
set_resolved_function(std::forward<Key>(key), mem_ptr, std::forward<T>(obj));
return *this;
}
template<typename... Sig, typename Fx, typename Key>
table& set_function(Key&& key, Fx&& fx) {
set_fx(types<Sig...>(), std::forward<Key>(key), std::forward<Fx>(fx));
return *this;
}
private:
template<typename R, typename... Args, typename Fx, typename Key, typename = typename std::result_of<Fx(Args...)>::type>
void set_fx(types<R(Args...)>, Key&& key, Fx&& fx) {
set_resolved_function<R(Args...)>(std::forward<Key>(key), std::forward<Fx>(fx));
}
template<typename Fx, typename Key>
void set_fx(types<>, Key&& key, Fx&& fx) {
typedef Unqualified<Unwrap<Fx>> fx_t;
typedef decltype(&fx_t::operator()) Sig;
set_fx(types<function_signature_t<Sig>>(), std::forward<Key>(key), std::forward<Fx>(fx));
}
template<typename... Sig, typename... Args, typename Key>
void set_resolved_function(Key&& key, Args&&... args) {
std::string fkey(std::forward<Key>(key));
push();
int tabletarget = lua_gettop(state());
stack::push<function_sig_t<Sig...>>(state(), std::forward<Args>(args)...);
lua_setfield(state(), tabletarget, fkey.c_str());
pop();
}
};
typedef table_core<false> table;
} // sol
#endif // SOL_TABLE_HPP

224
sol/table_core.hpp Normal file
View File

@ -0,0 +1,224 @@
// The MIT License (MIT)
// Copyright (c) 2013-2015 Danny Y., Rapptz
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef SOL_TABLE_CORE_HPP
#define SOL_TABLE_CORE_HPP
#include "proxy.hpp"
#include "stack.hpp"
#include "function_types.hpp"
#include "usertype.hpp"
namespace sol {
namespace detail {
struct global_overload_tag { } const global_overload;
} // detail
template <bool top_level>
class table_core : public reference {
friend class state;
template<typename T, typename Key, EnableIf<Not<std::is_arithmetic<Unqualified<Key>>>, Bool<top_level>> = 0>
stack::get_return<T> single_get( Key&& key ) const {
lua_getglobal( lua_state( ), &key[ 0 ] );
stack::get_return<T> result = stack::pop<T>( lua_state( ) );
return result;
}
template<typename T, typename Key, DisableIf<Not<std::is_arithmetic<Unqualified<Key>>>, Bool<top_level>> = 0>
stack::get_return<T> single_get( Key&& key ) const {
push( );
stack::push( lua_state( ), std::forward<Key>( key ) );
lua_gettable( lua_state( ), -2 );
stack::get_return<T> result = stack::pop<T>( lua_state( ) );
pop( );
return result;
}
template<typename Keys, typename... Ret, std::size_t... I>
stack::get_return<Ret...> tuple_get( types<Ret...>, indices<I...>, Keys&& keys ) const {
return stack::get_return<Ret...>( single_get<Ret>( std::get<I>( keys ) )... );
}
template<typename Keys, typename Ret, std::size_t I>
stack::get_return<Ret> tuple_get( types<Ret>, indices<I>, Keys&& keys ) const {
return single_get<Ret>( std::get<I>( keys ) );
}
#if SOL_LUA_VERSION < 502
table_core( detail::global_overload_tag, const table_core<false>& reg ) noexcept : reference( reg.lua_state(), LUA_GLOBALSINDEX ) { }
#else
table_core( detail::global_overload_tag, const table& reg ) noexcept : reference( reg.get<table>( LUA_RIDX_GLOBALS ) ) { }
#endif
public:
table_core( ) noexcept : reference( ) { }
table_core( const table_core<true>& global ) : reference( global ) { }
table_core( lua_State* L, int index = -1 ) : reference( L, index ) {
type_assert( L, index, type::table );
}
template<typename... Ret, typename... Keys>
stack::get_return<Ret...> get( Keys&&... keys ) const {
return tuple_get( types<Ret...>( ), build_indices<sizeof...( Ret )>( ), std::tie( keys... ) );
}
template<typename T, typename U>
table_core& set( T&& key, U&& value ) {
if ( top_level ) {
stack::push( lua_state( ), std::forward<U>( value ) );
lua_setglobal( lua_state( ), &key[0] );
}
else {
push( );
stack::push( lua_state( ), std::forward<T>( key ) );
stack::push( lua_state( ), std::forward<U>( value ) );
lua_settable( lua_state( ), -3 );
pop( );
}
return *this;
}
template<typename T>
SOL_DEPRECATED table_core& set_userdata( usertype<T>& user ) {
return set_usertype( user );
}
template<typename Key, typename T>
SOL_DEPRECATED table_core& set_userdata( Key&& key, usertype<T>& user ) {
return set_usertype( std::forward<Key>( key ), user );
}
template<typename T>
table_core& set_usertype( usertype<T>& user ) {
return set_usertype( usertype_traits<T>::name, user );
}
template<typename Key, typename T>
table_core& set_usertype( Key&& key, usertype<T>& user ) {
if ( top_level ) {
stack::push( lua_state( ), user );
lua_setglobal( lua_state( ), &key[ 0 ] );
pop( );
}
else {
push( );
stack::push( lua_state( ), std::forward<Key>( key ) );
stack::push( lua_state( ), user );
lua_settable( lua_state( ), -3 );
pop( );
}
return *this;
}
template<typename Fx>
void for_each( Fx&& fx ) const {
push( );
stack::push( lua_state( ), nil );
while ( lua_next( this->lua_state( ), -2 ) ) {
sol::object key( lua_state( ), -2 );
sol::object value( lua_state( ), -1 );
fx( key, value );
lua_pop( lua_state( ), 1 );
}
pop( );
}
size_t size( ) const {
push( );
size_t result = lua_rawlen( lua_state( ), -1 );
pop( );
return result;
}
template<typename T>
proxy<table_core, T> operator[]( T&& key ) {
return proxy<table_core, T>( *this, std::forward<T>( key ) );
}
template<typename T>
proxy<const table_core, T> operator[]( T&& key ) const {
return proxy<const table_core, T>( *this, std::forward<T>( key ) );
}
void pop( int n = 1 ) const noexcept {
lua_pop( lua_state( ), n );
}
template<typename... Args, typename R, typename Key>
table_core& set_function( Key&& key, R fun_ptr( Args... ) ) {
set_resolved_function( std::forward<Key>( key ), fun_ptr );
return *this;
}
template<typename Sig, typename Key>
table_core& set_function( Key&& key, Sig* fun_ptr ) {
set_resolved_function( std::forward<Key>( key ), fun_ptr );
return *this;
}
template<typename... Args, typename R, typename C, typename T, typename Key>
table_core& set_function( Key&& key, R( C::*mem_ptr )( Args... ), T&& obj ) {
set_resolved_function( std::forward<Key>( key ), mem_ptr, std::forward<T>( obj ) );
return *this;
}
template<typename Sig, typename C, typename T, typename Key>
table_core& set_function( Key&& key, Sig C::* mem_ptr, T&& obj ) {
set_resolved_function( std::forward<Key>( key ), mem_ptr, std::forward<T>( obj ) );
return *this;
}
template<typename... Sig, typename Fx, typename Key>
table_core& set_function( Key&& key, Fx&& fx ) {
set_fx( types<Sig...>( ), std::forward<Key>( key ), std::forward<Fx>( fx ) );
return *this;
}
private:
template<typename R, typename... Args, typename Fx, typename Key, typename = typename std::result_of<Fx( Args... )>::type>
void set_fx( types<R( Args... )>, Key&& key, Fx&& fx ) {
set_resolved_function<R( Args... )>( std::forward<Key>( key ), std::forward<Fx>( fx ) );
}
template<typename Fx, typename Key>
void set_fx( types<>, Key&& key, Fx&& fx ) {
typedef Unqualified<Unwrap<Fx>> fx_t;
typedef decltype( &fx_t::operator() ) Sig;
set_fx( types<function_signature_t<Sig>>( ), std::forward<Key>( key ), std::forward<Fx>( fx ) );
}
template<typename... Sig, typename... Args, typename Key, EnableIf<Not<std::is_arithmetic<Unqualified<Key>>>, Bool<top_level>> = 0>
void set_resolved_function( Key&& key, Args&&... args ) {
stack::push<function_sig_t<Sig...>>( lua_state( ), std::forward<Args>( args )... );
lua_setglobal( lua_state( ), &key[ 0 ] );
}
template<typename... Sig, typename... Args, typename Key, DisableIf<Not<std::is_arithmetic<Unqualified<Key>>>, Bool<top_level>> = 0>
void set_resolved_function( Key&& key, Args&&... args ) {
push( );
int tabletarget = lua_gettop( lua_state( ) );
stack::push<function_sig_t<Sig...>>( lua_state( ), std::forward<Args>( args )... );
lua_setfield( lua_state( ), tabletarget, &key[ 0 ] );
pop( );
}
};
} // sol
#endif // SOL_TABLE_CORE_HPP

View File

@ -121,7 +121,10 @@ inline std::string type_name(lua_State*L, type t) {
template<typename T>
class usertype;
class table;
template <bool>
class table_core;
typedef table_core<false> table;
typedef table_core<true> global_table;
class function;
class object;

View File

@ -597,7 +597,7 @@ TEST_CASE("tables/operator[]", "Check if operator[] retrieval and setting works
std::cout << a << ',' << b << '\n';
};
REQUIRE_NOTHROW(assert1(lua.global_table()));
REQUIRE_NOTHROW(assert1(lua.global()));
}
TEST_CASE("tables/usertype", "Show that we can create classes from usertype and use them") {