Objective C will always haunt me.

This commit is contained in:
ThePhD 2019-05-26 13:32:28 -04:00
parent 4fd5d34c57
commit a49fbc2f04
No known key found for this signature in database
GPG Key ID: 1509DB1C0F702BFA
10 changed files with 32 additions and 25 deletions

View File

@ -60,7 +60,7 @@ These allow a person to compare an ``sol::object`` against :ref:`nil<nil>`, whic
.. code-block:: cpp .. code-block:: cpp
if (myobj == sol::nil) { if (myobj == sol::lua_nil) {
// doesn't have anything... // doesn't have anything...
} }

View File

@ -70,7 +70,7 @@ This enumeration contains the status of a load operation from :ref:`state::load(
enum class type : int { enum class type : int {
none = LUA_TNONE, none = LUA_TNONE,
nil = LUA_TNIL, lua_nil = LUA_TNIL,
string = LUA_TSTRING, string = LUA_TSTRING,
number = LUA_TNUMBER, number = LUA_TNUMBER,
thread = LUA_TTHREAD, thread = LUA_TTHREAD,
@ -80,7 +80,9 @@ This enumeration contains the status of a load operation from :ref:`state::load(
lightuserdata = LUA_TLIGHTUSERDATA, lightuserdata = LUA_TLIGHTUSERDATA,
table = LUA_TTABLE, table = LUA_TTABLE,
poly = none | nil | string | number | thread | 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). 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 :caption: nil
:name: nil :name: nil
strunil_t {}; struct lua_nil_t {};
const nil_t nil {}; constexpr lua_nil_t lua_nil {};
bool operator==(nil_t, nil_t); bool operator==(lua_nil_t, lua_nil_t);
bool operator!=(nil_t, 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>`. ``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>`.

View File

@ -318,7 +318,7 @@ It can be used like so, inconjunction with ``sol::this_state``:
bool do_triple = a.as<bool>(); bool do_triple = a.as<bool>();
return sol::make_object(lua, b.as<double>() * ( do_triple ? 3 : 1 ) ); 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 () { int main () {

View File

@ -61,7 +61,7 @@ This example pretty much sums up what can be done. Note that the syntax ``lua["n
:linenos: :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 .. literalinclude:: ../../../examples/source/tutorials/erase_demo.cpp
:linenos: :linenos:

View File

@ -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)); return sol::object(lua, sol::in_place_type<double>, b.as<double>() * (do_triple ? 3 : 1));
} }
// Can also use make_object // Can also use make_object
return sol::make_object(lua, sol::nil); return sol::make_object(lua, sol::lua_nil);
} }
int main() { int main() {

View File

@ -8,7 +8,7 @@ int main() {
sol::optional<int> x = lua["bark"]; sol::optional<int> x = lua["bark"];
// x will have a value // x will have a value
lua["bark"] = sol::nil; lua["bark"] = sol::lua_nil;
sol::optional<int> y = lua["bark"]; sol::optional<int> y = lua["bark"];
// y will not have a value // y will not have a value

View File

@ -142,7 +142,7 @@ namespace sol {
if constexpr (sizeof...(Keys) > 0) { if constexpr (sizeof...(Keys) > 0) {
if constexpr ((mode & detail::insert_mode::create_if_nil) == detail::insert_mode::create_if_nil) { if constexpr ((mode & detail::insert_mode::create_if_nil) == detail::insert_mode::create_if_nil) {
type t = type_of(L, -1); 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); lua_pop(L, 1);
stack::push(L, new_table(0, 0)); stack::push(L, new_table(0, 0));
} }
@ -152,7 +152,7 @@ namespace sol {
else { else {
if constexpr ((mode & detail::insert_mode::create_if_nil) == detail::insert_mode::create_if_nil) { if constexpr ((mode & detail::insert_mode::create_if_nil) == detail::insert_mode::create_if_nil) {
type t = type_of(L, -1); 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); lua_pop(L, 1);
stack::push(L, new_table(0, 0)); stack::push(L, new_table(0, 0));
} }

View File

@ -97,16 +97,16 @@ namespace sol {
} // namespace detail } // namespace detail
struct lua_nil_t {}; 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) { inline bool operator==(lua_nil_t, lua_nil_t) {
return true; return true;
} }
inline bool operator!=(lua_nil_t, lua_nil_t) { inline bool operator!=(lua_nil_t, lua_nil_t) {
return false; return false;
} }
typedef lua_nil_t nil_t;
#if !defined(SOL_NO_NIL) || (SOL_NO_NIL == 0) #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 #endif
namespace detail { namespace detail {

View File

@ -20,8 +20,8 @@
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// This file was generated with a script. // This file was generated with a script.
// Generated 2019-05-23 08:33:03.489892 UTC // Generated 2019-05-26 17:32:11.611420 UTC
// This header was generated with sol v3.0.2 (revision cda8e02) // This header was generated with sol v3.0.2 (revision 4fd5d34)
// https://github.com/ThePhD/sol2 // https://github.com/ThePhD/sol2
#ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP #ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP

View File

@ -20,8 +20,8 @@
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// This file was generated with a script. // This file was generated with a script.
// Generated 2019-05-23 08:33:02.664806 UTC // Generated 2019-05-26 17:32:11.338294 UTC
// This header was generated with sol v3.0.2 (revision cda8e02) // This header was generated with sol v3.0.2 (revision 4fd5d34)
// https://github.com/ThePhD/sol2 // https://github.com/ThePhD/sol2
#ifndef SOL_SINGLE_INCLUDE_HPP #ifndef SOL_SINGLE_INCLUDE_HPP
@ -6288,16 +6288,16 @@ namespace sol {
} // namespace detail } // namespace detail
struct lua_nil_t {}; 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) { inline bool operator==(lua_nil_t, lua_nil_t) {
return true; return true;
} }
inline bool operator!=(lua_nil_t, lua_nil_t) { inline bool operator!=(lua_nil_t, lua_nil_t) {
return false; return false;
} }
typedef lua_nil_t nil_t;
#if !defined(SOL_NO_NIL) || (SOL_NO_NIL == 0) #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 #endif
namespace detail { namespace detail {
@ -22476,7 +22476,7 @@ namespace sol {
if constexpr (sizeof...(Keys) > 0) { if constexpr (sizeof...(Keys) > 0) {
if constexpr ((mode & detail::insert_mode::create_if_nil) == detail::insert_mode::create_if_nil) { if constexpr ((mode & detail::insert_mode::create_if_nil) == detail::insert_mode::create_if_nil) {
type t = type_of(L, -1); 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); lua_pop(L, 1);
stack::push(L, new_table(0, 0)); stack::push(L, new_table(0, 0));
} }
@ -22486,7 +22486,7 @@ namespace sol {
else { else {
if constexpr ((mode & detail::insert_mode::create_if_nil) == detail::insert_mode::create_if_nil) { if constexpr ((mode & detail::insert_mode::create_if_nil) == detail::insert_mode::create_if_nil) {
type t = type_of(L, -1); 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); lua_pop(L, 1);
stack::push(L, new_table(0, 0)); stack::push(L, new_table(0, 0));
} }