mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
Objective C will always haunt me.
This commit is contained in:
parent
4fd5d34c57
commit
a49fbc2f04
|
@ -60,7 +60,7 @@ These allow a person to compare an ``sol::object`` against :ref:`nil<nil>`, whic
|
|||
|
||||
.. code-block:: cpp
|
||||
|
||||
if (myobj == sol::nil) {
|
||||
if (myobj == sol::lua_nil) {
|
||||
// doesn't have anything...
|
||||
}
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ This enumeration contains the status of a load operation from :ref:`state::load(
|
|||
|
||||
enum class type : int {
|
||||
none = LUA_TNONE,
|
||||
nil = LUA_TNIL,
|
||||
lua_nil = LUA_TNIL,
|
||||
string = LUA_TSTRING,
|
||||
number = LUA_TNUMBER,
|
||||
thread = LUA_TTHREAD,
|
||||
|
@ -80,7 +80,9 @@ This enumeration contains the status of a load operation from :ref:`state::load(
|
|||
lightuserdata = LUA_TLIGHTUSERDATA,
|
||||
table = LUA_TTABLE,
|
||||
poly = none | nil | string | number | thread |
|
||||
table | boolean | function | userdata | lightuserdata
|
||||
table | boolean | function | userdata | lightuserdata,
|
||||
// if not in Objective C land...
|
||||
nil = LUA_TNIL
|
||||
};
|
||||
|
||||
The base types that Lua natively communicates in and understands. Note that "poly" isn't really a true type, it's just a symbol used in sol for something whose type hasn't been checked (and you should almost never see it).
|
||||
|
@ -118,10 +120,15 @@ special types
|
|||
:caption: nil
|
||||
:name: nil
|
||||
|
||||
strunil_t {};
|
||||
const nil_t nil {};
|
||||
bool operator==(nil_t, nil_t);
|
||||
bool operator!=(nil_t, nil_t);
|
||||
struct lua_nil_t {};
|
||||
constexpr lua_nil_t lua_nil {};
|
||||
bool operator==(lua_nil_t, lua_nil_t);
|
||||
bool operator!=(lua_nil_t, lua_nil_t);
|
||||
|
||||
// if not in Objective-C land
|
||||
using nil_t = lua_nil_t;
|
||||
constexpr nil_t nil {};
|
||||
|
||||
|
||||
``nil`` is a constant used to signify Lua's ``nil``, which is a type and object that something does not exist. It is comparable to itself, :doc:`sol::object<object>` and :doc:`proxy values<proxy>`.
|
||||
|
||||
|
|
|
@ -318,7 +318,7 @@ It can be used like so, inconjunction with ``sol::this_state``:
|
|||
bool do_triple = a.as<bool>();
|
||||
return sol::make_object(lua, b.as<double>() * ( do_triple ? 3 : 1 ) );
|
||||
}
|
||||
return sol::make_object(lua, sol::nil);
|
||||
return sol::make_object(lua, sol::lua_nil);
|
||||
}
|
||||
|
||||
int main () {
|
||||
|
|
|
@ -61,7 +61,7 @@ This example pretty much sums up what can be done. Note that the syntax ``lua["n
|
|||
:linenos:
|
||||
|
||||
|
||||
Finally, it's possible to erase a reference/variable by setting it to ``nil``, using the constant ``sol::nil`` in C++:
|
||||
Finally, it's possible to erase a reference/variable by setting it to ``nil``, using the constant ``sol::lua_nil`` in C++:
|
||||
|
||||
.. literalinclude:: ../../../examples/source/tutorials/erase_demo.cpp
|
||||
:linenos:
|
||||
|
|
|
@ -17,7 +17,7 @@ sol::object fancy_func(sol::object a, sol::object b, sol::this_state s) {
|
|||
return sol::object(lua, sol::in_place_type<double>, b.as<double>() * (do_triple ? 3 : 1));
|
||||
}
|
||||
// Can also use make_object
|
||||
return sol::make_object(lua, sol::nil);
|
||||
return sol::make_object(lua, sol::lua_nil);
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
|
|
@ -8,7 +8,7 @@ int main() {
|
|||
sol::optional<int> x = lua["bark"];
|
||||
// x will have a value
|
||||
|
||||
lua["bark"] = sol::nil;
|
||||
lua["bark"] = sol::lua_nil;
|
||||
sol::optional<int> y = lua["bark"];
|
||||
// y will not have a value
|
||||
|
||||
|
|
|
@ -142,7 +142,7 @@ namespace sol {
|
|||
if constexpr (sizeof...(Keys) > 0) {
|
||||
if constexpr ((mode & detail::insert_mode::create_if_nil) == detail::insert_mode::create_if_nil) {
|
||||
type t = type_of(L, -1);
|
||||
if (t == type::nil || t == type::none) {
|
||||
if (t == type::lua_nil || t == type::none) {
|
||||
lua_pop(L, 1);
|
||||
stack::push(L, new_table(0, 0));
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ namespace sol {
|
|||
else {
|
||||
if constexpr ((mode & detail::insert_mode::create_if_nil) == detail::insert_mode::create_if_nil) {
|
||||
type t = type_of(L, -1);
|
||||
if ((t == type::nil || t == type::none) && (is_table_like_v<T>)) {
|
||||
if ((t == type::lua_nil || t == type::none) && (is_table_like_v<T>)) {
|
||||
lua_pop(L, 1);
|
||||
stack::push(L, new_table(0, 0));
|
||||
}
|
||||
|
|
|
@ -97,16 +97,16 @@ namespace sol {
|
|||
} // namespace detail
|
||||
|
||||
struct lua_nil_t {};
|
||||
const lua_nil_t lua_nil{};
|
||||
constexpr lua_nil_t lua_nil{};
|
||||
inline bool operator==(lua_nil_t, lua_nil_t) {
|
||||
return true;
|
||||
}
|
||||
inline bool operator!=(lua_nil_t, lua_nil_t) {
|
||||
return false;
|
||||
}
|
||||
typedef lua_nil_t nil_t;
|
||||
#if !defined(SOL_NO_NIL) || (SOL_NO_NIL == 0)
|
||||
const nil_t nil{};
|
||||
using nil_t = lua_nil_t;
|
||||
constexpr nil_t& nil = lua_nil;
|
||||
#endif
|
||||
|
||||
namespace detail {
|
||||
|
|
|
@ -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 2019-05-23 08:33:03.489892 UTC
|
||||
// This header was generated with sol v3.0.2 (revision cda8e02)
|
||||
// Generated 2019-05-26 17:32:11.611420 UTC
|
||||
// This header was generated with sol v3.0.2 (revision 4fd5d34)
|
||||
// https://github.com/ThePhD/sol2
|
||||
|
||||
#ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP
|
||||
|
|
|
@ -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 2019-05-23 08:33:02.664806 UTC
|
||||
// This header was generated with sol v3.0.2 (revision cda8e02)
|
||||
// Generated 2019-05-26 17:32:11.338294 UTC
|
||||
// This header was generated with sol v3.0.2 (revision 4fd5d34)
|
||||
// https://github.com/ThePhD/sol2
|
||||
|
||||
#ifndef SOL_SINGLE_INCLUDE_HPP
|
||||
|
@ -6288,16 +6288,16 @@ namespace sol {
|
|||
} // namespace detail
|
||||
|
||||
struct lua_nil_t {};
|
||||
const lua_nil_t lua_nil{};
|
||||
constexpr lua_nil_t lua_nil{};
|
||||
inline bool operator==(lua_nil_t, lua_nil_t) {
|
||||
return true;
|
||||
}
|
||||
inline bool operator!=(lua_nil_t, lua_nil_t) {
|
||||
return false;
|
||||
}
|
||||
typedef lua_nil_t nil_t;
|
||||
#if !defined(SOL_NO_NIL) || (SOL_NO_NIL == 0)
|
||||
const nil_t nil{};
|
||||
using nil_t = lua_nil_t;
|
||||
constexpr nil_t& nil = lua_nil;
|
||||
#endif
|
||||
|
||||
namespace detail {
|
||||
|
@ -22476,7 +22476,7 @@ namespace sol {
|
|||
if constexpr (sizeof...(Keys) > 0) {
|
||||
if constexpr ((mode & detail::insert_mode::create_if_nil) == detail::insert_mode::create_if_nil) {
|
||||
type t = type_of(L, -1);
|
||||
if (t == type::nil || t == type::none) {
|
||||
if (t == type::lua_nil || t == type::none) {
|
||||
lua_pop(L, 1);
|
||||
stack::push(L, new_table(0, 0));
|
||||
}
|
||||
|
@ -22486,7 +22486,7 @@ namespace sol {
|
|||
else {
|
||||
if constexpr ((mode & detail::insert_mode::create_if_nil) == detail::insert_mode::create_if_nil) {
|
||||
type t = type_of(L, -1);
|
||||
if ((t == type::nil || t == type::none) && (is_table_like_v<T>)) {
|
||||
if ((t == type::lua_nil || t == type::none) && (is_table_like_v<T>)) {
|
||||
lua_pop(L, 1);
|
||||
stack::push(L, new_table(0, 0));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user