sol2/docs/source/index.rst

109 lines
2.3 KiB
ReStructuredText
Raw Normal View History

2016-03-12 06:47:15 +08:00
.. Sol documentation master file, created by
sphinx-quickstart on Mon Feb 29 21:49:51 2016.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
2016-03-13 21:03:47 +08:00
Sol 2.0
=======
2016-03-12 06:47:15 +08:00
a fast, simple C++ and Lua Binding
----------------------------------
2016-03-12 10:45:41 +08:00
When you need to hit the ground running with Lua and C++, `Sol`_ is the go-to framework for high-performance binding with an easy to use API.
2016-03-13 21:03:47 +08:00
.. image:: https://travis-ci.org/ThePhD/sol2.svg?branch=develop
:target: https://travis-ci.org/ThePhD/sol2
:alt: build status
2016-03-12 10:45:41 +08:00
get going:
----------
2016-03-12 06:47:15 +08:00
.. toctree::
:maxdepth: 1
:name: mastertoc
2016-03-12 10:45:41 +08:00
api/top
2016-03-12 06:47:15 +08:00
features
benchmarks
exceptions
rtti
licenses
2016-03-12 10:45:41 +08:00
2016-03-12 06:47:15 +08:00
"I need feature X, maybe you have it?"
--------------------------------------
2016-03-12 10:45:41 +08:00
Take a look at the :doc:`Features<features>` page: it links to much of the API. You can also just straight up browse the API. Don't see a feature you want? Send inquiries for support for a particular abstraction to the `issues`_ tracker.
2016-03-12 06:47:15 +08:00
2016-03-12 10:45:41 +08:00
the basics:
2016-03-12 06:47:15 +08:00
-----------
.. note::
More examples can be found in the `examples directory`_
.. code-block:: c++
:caption: functions
:linenos:
#include <sol.hpp>
#include <cassert>
int main() {
sol::state lua;
int x = 0;
lua.set_function("beep", [&x]{ ++x; });
lua.script("beep()");
assert(x == 1);
sol::function beep = lua["beep"];
beep();
assert(x == 2);
return 0;
}
.. code-block:: c++
:caption: linking C++ structures to Lua
:linenos:
#include <sol.hpp>
#include <cassert>
struct vars {
int boop = 0;
int bop () const {
return boop + 1;
}
};
int main() {
sol::state lua;
lua.new_usertype<vars>("vars",
"boop", &vars::boop
"bop", &vars::bop);
lua.script("beep = vars.new()\n"
"beep.boop = 1\n"
"bopvalue = beep:bop()");
2016-03-12 06:47:15 +08:00
vars& beep = lua["beep"];
int bopvalue = lua["bopvalue"];
assert(beep.boop == 1);
assert(lua.get<vars>("beep").boop == 1);
assert(beep.bop() == 2);
assert(bopvalue == 2);
return 0;
}
Indices and tables
==================
* :ref:`genindex`
* :ref:`search`
2016-03-12 10:45:41 +08:00
.. _Sol: https://github.com/ThePhD/sol2
.. _issues: https://github.com/ThePhD/sol2/issues
2016-03-12 06:47:15 +08:00
.. _examples directory: https://github.com/ThePhD/sol2/tree/develop/examples