From fe8f19631e43b017fea7f2be121c0acfbeb31371 Mon Sep 17 00:00:00 2001 From: ThePhD Date: Sat, 9 Apr 2016 01:21:16 -0400 Subject: [PATCH] Erase-a-var documentation. --- docs/source/tutorial/variables.rst | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/source/tutorial/variables.rst b/docs/source/tutorial/variables.rst index 09ef5c81..d1c5aa56 100644 --- a/docs/source/tutorial/variables.rst +++ b/docs/source/tutorial/variables.rst @@ -178,4 +178,24 @@ This example pretty much sums up what can be done. Note that the syntax ``lua["n } } +Finally, it's possible to erase a reference/variable by setting it to ``nil``, using the constant ``sol::nil`` in C++: + +.. code-block:: cpp + :caption: main.cpp + :name: erase-main-cpp + + #include + + int main () { + + sol::state lua; + lua["bark"] = 50; + sol::optional x = lua["bark"]; + // x will have a value + + lua["bark"] = sol::nil; + sol::optional y = lua["bark"]; + // y will not have a value + } + It's easy to see that there's a lot of options to do what you want here. But, these are just traditional numbers and strings. What if we want more power, more capabilities than what these limited types can offer us? Let's throw some :doc:`functions in there` :doc:`C++ classes into the mix`! \ No newline at end of file