mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
fix overpop from stack_check_get tracking
This commit is contained in:
parent
ab5b417fb0
commit
e8e5ddc890
|
@ -12,7 +12,10 @@ sol::table open_mylib(sol::this_state s) {
|
|||
sol::state_view lua(s);
|
||||
|
||||
sol::table module = lua.create_table();
|
||||
module["func"] = []() { /* super cool function here */ };
|
||||
module["func"] = []() {
|
||||
/* super cool function here */
|
||||
return 2;
|
||||
};
|
||||
// register a class too
|
||||
module.new_usertype<some_class>("some_class",
|
||||
"bark", &some_class::bark
|
||||
|
@ -25,18 +28,20 @@ int main() {
|
|||
std::cout << "=== require example ===" << std::endl;
|
||||
|
||||
sol::state lua;
|
||||
lua.open_libraries(sol::lib::package);
|
||||
lua.open_libraries(sol::lib::package, sol::lib::base);
|
||||
// sol::c_call takes functions at the template level
|
||||
// and turns it into a lua_CFunction
|
||||
// alternatively, one can use sol::c_call<sol::wrap<callable_struct, callable_struct{}>> to make the call
|
||||
// if it's a constexpr struct
|
||||
lua.require("my_lib", sol::c_call<decltype(&open_mylib), &open_mylib>);
|
||||
|
||||
// do ALL THE THINGS YOU LIKE
|
||||
lua.script(R"(
|
||||
// run some code against your require'd library
|
||||
lua.safe_script(R"(
|
||||
s = my_lib.some_class.new()
|
||||
s.bark = 20;
|
||||
assert(my_lib.func() == 2)
|
||||
s.bark = 20
|
||||
)");
|
||||
|
||||
some_class& s = lua["s"];
|
||||
c_assert(s.bark == 20);
|
||||
std::cout << "s.bark = " << s.bark << std::endl;
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
// This file was generated with a script.
|
||||
// Generated 2018-03-03 20:38:52.222840 UTC
|
||||
// This header was generated with sol v2.19.5 (revision 2e1fcd3)
|
||||
// Generated 2018-03-04 10:40:19.748536 UTC
|
||||
// This header was generated with sol v2.19.5 (revision ab5b417)
|
||||
// https://github.com/ThePhD/sol2
|
||||
|
||||
#ifndef SOL_SINGLE_INCLUDE_HPP
|
||||
|
@ -9472,12 +9472,12 @@ namespace stack {
|
|||
struct check_getter<T, std::enable_if_t<is_lua_reference<T>::value>> {
|
||||
template <typename Handler>
|
||||
static optional<T> get(lua_State* L, int index, Handler&& handler, record& tracking) {
|
||||
tracking.use(1);
|
||||
// actually check if it's none here, otherwise
|
||||
// we'll have a nil object inside an optional!
|
||||
bool success = !lua_isnoneornil(L, index);
|
||||
if (!success) {
|
||||
// expected type, actual type
|
||||
tracking.use(static_cast<int>(!lua_isnone(L, index)));
|
||||
handler(L, index, type::poly, type_of(L, index), "");
|
||||
return nullopt;
|
||||
}
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
// This file was generated with a script.
|
||||
// Generated 2018-03-03 20:38:52.449565 UTC
|
||||
// This header was generated with sol v2.19.5 (revision 2e1fcd3)
|
||||
// Generated 2018-03-04 10:40:19.971825 UTC
|
||||
// This header was generated with sol v2.19.5 (revision ab5b417)
|
||||
// https://github.com/ThePhD/sol2
|
||||
|
||||
#ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP
|
||||
|
|
|
@ -51,12 +51,12 @@ namespace stack {
|
|||
struct check_getter<T, std::enable_if_t<is_lua_reference<T>::value>> {
|
||||
template <typename Handler>
|
||||
static optional<T> get(lua_State* L, int index, Handler&& handler, record& tracking) {
|
||||
tracking.use(1);
|
||||
// actually check if it's none here, otherwise
|
||||
// we'll have a nil object inside an optional!
|
||||
bool success = !lua_isnoneornil(L, index);
|
||||
if (!success) {
|
||||
// expected type, actual type
|
||||
tracking.use(static_cast<int>(!lua_isnone(L, index)));
|
||||
handler(L, index, type::poly, type_of(L, index), "");
|
||||
return nullopt;
|
||||
}
|
||||
|
|
24
sol2.natvis
Normal file
24
sol2.natvis
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
|
||||
<Type Name="sol::optional<*>">
|
||||
<DisplayString Condition="init_ == false">empty</DisplayString>
|
||||
<DisplayString>{*((value_type*)(&storage_[0]))}</DisplayString>
|
||||
<Expand>
|
||||
<Item Name="value" Condition="init_ == true">*((value_type*)(&storage_[0]))</Item>
|
||||
</Expand>
|
||||
</Type>
|
||||
<Type Name="sol::basic_reference<*>">
|
||||
<DisplayString>ref={ref} state={luastate}</DisplayString>
|
||||
<Expand>
|
||||
<Item Name="reference index">ref</Item>
|
||||
<Item Name="state">luastate</Item>
|
||||
</Expand>
|
||||
</Type>
|
||||
<Type Name="sol::stack_reference">
|
||||
<DisplayString>index={index} state={luastate}</DisplayString>
|
||||
<Expand>
|
||||
<Item Name="stack index">index</Item>
|
||||
<Item Name="state">luastate</Item>
|
||||
</Expand>
|
||||
</Type>
|
||||
</AutoVisualizer>
|
Loading…
Reference in New Issue
Block a user