diff options
author | 2017-02-05 16:01:50 +0100 | |
---|---|---|
committer | 2017-02-05 16:06:06 +0100 | |
commit | ac096aa2a0921efde96b76252dffb119dcf27efc (patch) | |
tree | 2ad9a28a7f6babce8cfcbf5995e3e055ff13ff60 /3rdparty/sol2/docs/source/tutorial | |
parent | 29df715138452ee18ba19ec4b07e18c4b3185de7 (diff) |
Update sol2 (nw)
Diffstat (limited to '3rdparty/sol2/docs/source/tutorial')
-rw-r--r-- | 3rdparty/sol2/docs/source/tutorial/all-the-things.rst | 26 | ||||
-rw-r--r-- | 3rdparty/sol2/docs/source/tutorial/variables.rst | 6 |
2 files changed, 16 insertions, 16 deletions
diff --git a/3rdparty/sol2/docs/source/tutorial/all-the-things.rst b/3rdparty/sol2/docs/source/tutorial/all-the-things.rst index 3695ac77fe2..3b764b8d2e9 100644 --- a/3rdparty/sol2/docs/source/tutorial/all-the-things.rst +++ b/3rdparty/sol2/docs/source/tutorial/all-the-things.rst @@ -133,7 +133,7 @@ Retrieve these variables using this syntax: std::string important_string = lua["important_string"]; // dig into a table - int value = lua["value"]["value"]; + int value = lua["some_table"]["value"]; // get a function sol::function a_function = lua["a_function"]; @@ -158,7 +158,7 @@ Retrieve Lua types using ``object`` and other ``sol::`` types. sol::object function_obj = lua[ "a_function" ]; // sol::type::function sol::type t2 = function_obj.get_type(); - bool is_it_really = function_obj.is<std::function<int()>(); // true + bool is_it_really = function_obj.is<std::function<int()>>(); // true // will not contain data sol::optional<int> check_for_me = lua["a_function"]; @@ -172,12 +172,11 @@ You can erase things by setting it to ``nullptr`` or ``sol::nil``. lua.script("exists = 250"); - int first_try = lua.get_or<int>( 322 ); + int first_try = lua.get_or( "exists", 322 ); // first_try == 250 lua.set("exists", sol::nil); - - int second_try = lua.get_or<int>( 322 ); + int second_try = lua.get_or( "exists", 322 ); // second_try == 322 @@ -224,12 +223,12 @@ If you're going deep, be safe: sol::optional<int> will_not_error = lua["abc"]["DOESNOTEXIST"]["ghi"]; // will_not_error == sol::nullopt - int will_not_error2 = lua["abc"]["def"]["ghi"]["jklm"].get_or<int>(25); + int also_will_not_error = lua["abc"]["def"]["ghi"]["jklm"].get_or(25); // is 25 // if you don't go safe, // will throw (or do at_panic if no exceptions) - int aaaahhh = lua["abc"]["hope_u_liek_crash"]; + int aaaahhh = lua["boom"]["the_dynamite"]; make tables @@ -423,7 +422,8 @@ multiple returns from lua std::tuple<int, int, int> result; result = lua["f"](100, 200, 300); // result == { 100, 200, 300 } - int a, int b; + int a; + int b; std::string c; sol::tie( a, b, c ) = lua["f"](100, 200, "bark"); // a == 100 @@ -447,7 +447,7 @@ multiple returns to lua // result == { 100, 200, 300 } std::tuple<int, int, std::string> result2; - result2 = lua["f"](100, 200, "BARK BARK BARK!") + result2 = lua["f"](100, 200, "BARK BARK BARK!"); // result2 == { 100, 200, "BARK BARK BARK!" } int a, int b; @@ -476,7 +476,7 @@ Is set as a :doc:`userdata + usertype<../api/usertype>`. struct Doge { int tailwag = 50; - } + }; Doge dog{}; @@ -504,7 +504,7 @@ Is set as a :doc:`userdata + usertype<../api/usertype>`. struct Doge { int tailwag = 50; - } + }; sol::state lua; lua.open_libraries(sol::lib::base); @@ -528,7 +528,7 @@ Get userdata in the same way as everything else: struct Doge { int tailwag = 50; - } + }; sol::state lua; lua.open_libraries(sol::lib::base); @@ -543,7 +543,7 @@ Note that you can change the data of usertype variables and it will affect thing struct Doge { int tailwag = 50; - } + }; sol::state lua; lua.open_libraries(sol::lib::base); diff --git a/3rdparty/sol2/docs/source/tutorial/variables.rst b/3rdparty/sol2/docs/source/tutorial/variables.rst index 20105bf8003..a911fcefdb4 100644 --- a/3rdparty/sol2/docs/source/tutorial/variables.rst +++ b/3rdparty/sol2/docs/source/tutorial/variables.rst @@ -60,7 +60,7 @@ You can interact with the variables like this: return 0; } -From this example, you can see that there's many ways to pull out the varaibles you want. You can get For example, to determine if a nested variable exists or not, you can use ``auto`` to capture the value of a ``table[key]`` lookup, and then use the ``.valid()`` method: +From this example, you can see that there's many ways to pull out the varaibles you want. For example, to determine if a nested variable exists or not, you can use ``auto`` to capture the value of a ``table[key]`` lookup, and then use the ``.valid()`` method: .. code-block:: cpp :caption: safe lookup @@ -83,7 +83,7 @@ This comes in handy when you want to check if a nested variable exists. You can // Branch not taken: value is not an integer } - sol::optoinal<bool> is_a_boolean = lua["config"]["fullscreen"]; + sol::optional<bool> is_a_boolean = lua["config"]["fullscreen"]; if (is_a_boolean) { // Branch taken: the value is a boolean } @@ -199,4 +199,4 @@ Finally, it's possible to erase a reference/variable by setting it to ``nil``, u // 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<functions>` :doc:`C++ classes into the mix<cxx-in-lua>`!
\ No newline at end of file +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<functions>` :doc:`C++ classes into the mix<cxx-in-lua>`! |