aboutsummaryrefslogtreecommitdiffstats
path: root/lib/sol2/docs/source/api/this_environment.rst
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2022-11-15 07:35:07 -0500
committerClyne Sullivan <clyne@bitgloo.com>2022-11-15 07:35:07 -0500
commita056c15dd3781b4f6bb89fdd738b14cafc00cd85 (patch)
tree1775a5913c7bc87563b6b4a29c63514cf15b4185 /lib/sol2/docs/source/api/this_environment.rst
parent1405d648b6264cfda7c46f5b251258335abaee83 (diff)
parent57013add5b7c524086272be7d395f9ec5109bde2 (diff)
merge branch lib-cleanup into ui
Diffstat (limited to 'lib/sol2/docs/source/api/this_environment.rst')
-rw-r--r--lib/sol2/docs/source/api/this_environment.rst46
1 files changed, 0 insertions, 46 deletions
diff --git a/lib/sol2/docs/source/api/this_environment.rst b/lib/sol2/docs/source/api/this_environment.rst
deleted file mode 100644
index de37a63..0000000
--- a/lib/sol2/docs/source/api/this_environment.rst
+++ /dev/null
@@ -1,46 +0,0 @@
-this_environment
-================
-*retrieving the environment of the calling function*
-
-
-Sometimes in C++ it's useful to know where a Lua call is coming from and what :doc:`environment<environment>` it is from. The former is covered by Lua's Debug API, which is extensive and is not fully wrapped up by sol3. But, sol3 covers the latter in letting you get the environment of the calling script / function, if it has one. ``sol::this_environment`` is a *transparent argument* and does not need to be passed in Lua scripts or provided when using :doc:`sol::function<function>`, similar to :doc:`sol::this_state<this_state>`:
-
-.. code-block:: cpp
- :linenos:
-
- #define SOL_ALL_SAFETIES_ON
- #include <sol/sol.hpp>
-
- #include <iostream>
-
-
- void env_check(sol::this_state ts, int x, sol::this_environment te) {
- std::cout << "In C++, 'int x' is in the second position, and its value is: " << x << std::endl;
- if (!te) {
- std::cout << "function does not have an environment: exiting function early" << std::endl;
- return;
- }
- sol::environment& env = te;
- sol::state_view lua = ts;
- sol::environment freshenv = lua["freshenv"];
- bool is_same_env = freshenv == env;
- std::cout << "env == freshenv : " << is_same_env << std::endl;
- }
-
- int main() {
- sol::state lua;
- sol::environment freshenv(lua, sol::create, lua.globals());
- lua["freshenv"] = freshenv;
-
- lua.set_function("f", env_check);
-
- // note that "f" only takes 1 argument and is okay here
- lua.script("f(25)", freshenv);
-
- return 0;
- }
-
-
-Also see `this example`_ for more details.
-
-.. _this example: https://github.com/ThePhD/sol2/blob/develop/examples/source/environment_snooping.cpp \ No newline at end of file