mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
add pointer()
method
This commit is contained in:
parent
db6b3238b5
commit
8a27648b77
|
@ -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-06-27 11:15:40.545352 UTC
|
||||
// This header was generated with sol v2.20.4 (revision 3935dc4)
|
||||
// Generated 2018-06-27 15:33:51.932186 UTC
|
||||
// This header was generated with sol v2.20.4 (revision 60ee53a)
|
||||
// https://github.com/ThePhD/sol2
|
||||
|
||||
#ifndef SOL_SINGLE_INCLUDE_HPP
|
||||
|
@ -5530,6 +5530,9 @@ namespace sol {
|
|||
template <>
|
||||
struct lua_type_of<void*> : std::integral_constant<type, type::lightuserdata> {};
|
||||
|
||||
template <>
|
||||
struct lua_type_of<const void*> : std::integral_constant<type, type::lightuserdata> {};
|
||||
|
||||
template <>
|
||||
struct lua_type_of<lightuserdata_value> : std::integral_constant<type, type::lightuserdata> {};
|
||||
|
||||
|
@ -6513,6 +6516,11 @@ namespace sol {
|
|||
return index;
|
||||
}
|
||||
|
||||
const void* pointer() const noexcept {
|
||||
const void* vp = lua_topointer(lua_state(), stack_index());
|
||||
return vp;
|
||||
}
|
||||
|
||||
type get_type() const noexcept {
|
||||
int result = lua_type(lua_state(), index);
|
||||
return static_cast<type>(result);
|
||||
|
@ -6957,6 +6965,12 @@ namespace sol {
|
|||
return !(ref == LUA_NOREF || ref == LUA_REFNIL);
|
||||
}
|
||||
|
||||
const void* pointer() const noexcept {
|
||||
int si = push();
|
||||
const void* vp = lua_topointer(lua_state(), -si);
|
||||
return vp;
|
||||
}
|
||||
|
||||
explicit operator bool() const noexcept {
|
||||
return valid();
|
||||
}
|
||||
|
@ -9843,6 +9857,14 @@ namespace stack {
|
|||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct getter<const void*> {
|
||||
static const void* get(lua_State* L, int index, record& tracking) {
|
||||
tracking.use(1);
|
||||
return lua_touserdata(L, index);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct getter<detail::as_value_tag<T>> {
|
||||
static T* get_no_lua_nil(lua_State* L, int index, record& tracking) {
|
||||
|
@ -10673,6 +10695,14 @@ namespace stack {
|
|||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pusher<const void*> {
|
||||
static int push(lua_State* L, const void* userdata) {
|
||||
lua_pushlightuserdata(L, const_cast<void*>(userdata));
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pusher<lightuserdata_value> {
|
||||
static int push(lua_State* L, lightuserdata_value userdata) {
|
||||
|
|
|
@ -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-06-27 11:15:40.807656 UTC
|
||||
// This header was generated with sol v2.20.4 (revision 3935dc4)
|
||||
// Generated 2018-06-27 15:33:52.214419 UTC
|
||||
// This header was generated with sol v2.20.4 (revision 60ee53a)
|
||||
// https://github.com/ThePhD/sol2
|
||||
|
||||
#ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP
|
||||
|
|
|
@ -429,6 +429,12 @@ namespace sol {
|
|||
return !(ref == LUA_NOREF || ref == LUA_REFNIL);
|
||||
}
|
||||
|
||||
const void* pointer() const noexcept {
|
||||
int si = push();
|
||||
const void* vp = lua_topointer(lua_state(), -si);
|
||||
return vp;
|
||||
}
|
||||
|
||||
explicit operator bool() const noexcept {
|
||||
return valid();
|
||||
}
|
||||
|
|
|
@ -739,6 +739,14 @@ namespace stack {
|
|||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct getter<const void*> {
|
||||
static const void* get(lua_State* L, int index, record& tracking) {
|
||||
tracking.use(1);
|
||||
return lua_touserdata(L, index);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct getter<detail::as_value_tag<T>> {
|
||||
static T* get_no_lua_nil(lua_State* L, int index, record& tracking) {
|
||||
|
|
|
@ -467,6 +467,14 @@ namespace stack {
|
|||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pusher<const void*> {
|
||||
static int push(lua_State* L, const void* userdata) {
|
||||
lua_pushlightuserdata(L, const_cast<void*>(userdata));
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pusher<lightuserdata_value> {
|
||||
static int push(lua_State* L, lightuserdata_value userdata) {
|
||||
|
|
|
@ -113,6 +113,11 @@ namespace sol {
|
|||
return index;
|
||||
}
|
||||
|
||||
const void* pointer() const noexcept {
|
||||
const void* vp = lua_topointer(lua_state(), stack_index());
|
||||
return vp;
|
||||
}
|
||||
|
||||
type get_type() const noexcept {
|
||||
int result = lua_type(lua_state(), index);
|
||||
return static_cast<type>(result);
|
||||
|
|
|
@ -950,6 +950,9 @@ namespace sol {
|
|||
template <>
|
||||
struct lua_type_of<void*> : std::integral_constant<type, type::lightuserdata> {};
|
||||
|
||||
template <>
|
||||
struct lua_type_of<const void*> : std::integral_constant<type, type::lightuserdata> {};
|
||||
|
||||
template <>
|
||||
struct lua_type_of<lightuserdata_value> : std::integral_constant<type, type::lightuserdata> {};
|
||||
|
||||
|
|
|
@ -134,6 +134,27 @@ TEST_CASE("utility/thread", "fire up lots of threads at the same time to make su
|
|||
}());
|
||||
}
|
||||
|
||||
TEST_CASE("utility/pointer", "check we can get pointer value from references") {
|
||||
sol::state lua;
|
||||
lua.set_function("f", [](bool aorb, sol::reference a, sol::stack_reference b) {
|
||||
if (aorb) {
|
||||
return a.pointer();
|
||||
}
|
||||
return b.pointer();
|
||||
});
|
||||
auto result0 = lua.safe_script("v0 = 'hi'", sol::script_pass_on_error);
|
||||
REQUIRE(result0.valid());
|
||||
auto result1 = lua.safe_script("v1 = f(true, v0)", sol::script_pass_on_error);
|
||||
REQUIRE(result1.valid());
|
||||
auto result2 = lua.safe_script("v2 = f(false, nil, v0)", sol::script_pass_on_error);
|
||||
REQUIRE(result2.valid());
|
||||
const void* ap = lua["v1"];
|
||||
const void* bp = lua["v2"];
|
||||
REQUIRE(ap != nullptr);
|
||||
REQUIRE(bp != nullptr);
|
||||
REQUIRE(ap == bp);
|
||||
}
|
||||
|
||||
TEST_CASE("utility/this_state", "Ensure this_state argument can be gotten anywhere in the function.") {
|
||||
struct bark {
|
||||
int with_state(sol::this_state l, int a, int b) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user