-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
227 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,8 @@ API Reference | |
.. toctree:: | ||
:maxdepth: 2 | ||
|
||
preprocessor_option | ||
state | ||
metatable | ||
luaref | ||
standard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
UserdataMetatable | ||
======================== | ||
|
||
|
||
.. doxygenclass:: kaguya::UserdataMetatable | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
|
||
Preprocessor Options | ||
================================== | ||
|
||
This option must be same between translation units. | ||
|
||
.. _preprocessor-use-cpp11: | ||
* KAGUYA_USE_CPP11 | ||
|
||
| If defined 1, kaguya use C++11 feature. | ||
| If defined 0, kaguya use C++03 only (need boost library). | ||
| default is auto detect (using _MSC_VER or __cplusplus). | ||
| | ||
* KAGUYA_NO_USERDATA_TYPE_CHECK | ||
|
||
If defined 1, Skip type check for userdata created without kaguya. | ||
|
||
.. warning:: | ||
|
||
This option is dangerous to be used in conjunction with other Lua library. | ||
|
||
example: | ||
|
||
.. code-block:: lua | ||
--io.stdin is created by lua standard libray. | ||
kaguya_binded_receive_userdata_fn(io.stdin) -- Error not detected. this is undefined behavior. | ||
| | ||
* KAGUYA_NO_VECTOR_AND_MAP_TO_TABLE | ||
|
||
If difined, std::map and std::vector will not be converted to a lua-table | ||
|
||
| | ||
* KAGUYA_NO_STD_VECTOR_TO_TABLE | ||
|
||
If difined, std::vector will not be converted to a lua-table | ||
|
||
| | ||
* KAGUYA_NO_STD_MAP_TO_TABLE | ||
|
||
If difined, std::map will not be converted to a lua-table | ||
|
||
| | ||
* KAGUYA_FUNCTION_MAX_ARGS | ||
|
||
Define max argument count for binding function. default is 9. | ||
|
||
.. note:: | ||
|
||
Effect in the C++03 only | ||
|
||
| | ||
* KAGUYA_FUNCTION_MAX_OVERLOADS | ||
|
||
Define max overloads function count for binding functions. default is 9. | ||
|
||
.. note:: | ||
|
||
Effect in the C++03 only |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
|
||
kaguya::standard namespace | ||
================================== | ||
|
||
This namespace store standard libraries. | ||
|
||
using boost library for not enough in C++03. | ||
|
||
In this way it has been defined in kaguya/config.hpp | ||
|
||
.. code-block:: c++ | ||
|
||
namespace kaguya | ||
{ | ||
namespace standard | ||
{ | ||
#if KAGUYA_USE_CPP11 | ||
using namespace std; | ||
#else | ||
using namespace boost; | ||
#endif | ||
} | ||
} | ||
|
||
|
||
Used switched types | ||
----------------------------- | ||
|
||
* tuple | ||
|
||
using multiple return value. | ||
|
||
* shared_ptr | ||
|
||
using shared_ptr assign. see :ref:`smartpointers<class-bindings-smartpointers>`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
|
||
State | ||
================================== | ||
State is lua_State* wrapper class | ||
|
||
.. doxygenclass:: kaguya::State | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
|
||
Class Bindings | ||
================================== | ||
C++ classes binding use :doc:`/api_reference/metatable`. | ||
|
||
|
||
A quick example | ||
------------------------- | ||
|
||
Exposing classes to Lua | ||
|
||
.. code-block:: c++ | ||
|
||
//C++ | ||
struct MyClass | ||
{ | ||
MyClass():x(0),y() {} | ||
MyClass(int x,const std::string& y):x(x),y(y) {} | ||
void setX(int v){x=v;} | ||
int getX()const{return x;} | ||
void setY(const char* v){y=v;} | ||
const std::string& getY()const{return y;} | ||
private: | ||
int x; | ||
std::string y; | ||
}; | ||
|
||
... | ||
state["MyClass"] = kaguya::UserdataMetatable<MyClass>() | ||
.setConstructors<MyClass(),MyClass(int,const std::string&)>() | ||
.addFunction("setX", &MyClass::setX) | ||
.addFunction("getX", &MyClass::getX) | ||
.addProperty("y", &MyClass::getY, &MyClass::setY) | ||
; | ||
|
||
|
||
Usage in Lua | ||
|
||
.. code-block:: lua | ||
local v = MyClass.new(4,'text') | ||
print(v:getX()) -- output 4 | ||
print(v.y) -- output 'text' | ||
Object lifetime | ||
------------------------- | ||
|
||
Copy assign | ||
^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
Basic assign. | ||
Copy object and managing lifetime by Lua. | ||
|
||
example: | ||
|
||
.. code-block:: c++ | ||
|
||
{ | ||
MyClass myobj; | ||
state["a"] = myobj; | ||
} | ||
state.dostring("print(a.y)");//myobj is destroyed, but a is living. | ||
state["a"] = 0;//override a. | ||
state.gc().collect(); //copied object is garbage collected. | ||
|
||
Pointer assign | ||
^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
You need managing object lifetime by yourself. | ||
|
||
broken code example: | ||
|
||
.. code-block:: c++ | ||
|
||
MyClass* myptr = new MyClass(); | ||
state["a"] = myptr; | ||
delete myptr; | ||
state.dostring("print(a.y)")// a is destroyed. This is undefined behavior as dangling pointer. | ||
|
||
|
||
Smartpointers | ||
^^^^^^^^^^^^^^^^^^^^^^ | ||
.. _class-bindings-smartpointers: | ||
|
||
If you think troublesome for managing lifetime, can use shared_ptr. | ||
|
||
.. code-block:: c++ | ||
|
||
kaguya::standard::shared_ptr<MyClass> mysptr = kaguya::standard::make_shared<MyClass>(); | ||
state["a"] = mysptr; | ||
state.dostring("print(a.y)"); | ||
|
||
.. note:: | ||
|
||
If :ref:`KAGUYA_USE_CPP11<preprocessor-use-cpp11>` is 0, | ||
std::shared_ptr(and std::tr1::shared_ptr) is unrecognized, and vice versa. | ||
see :doc:`/api_reference/standard` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ Getting Started | |
|
||
requirements | ||
tutorial | ||
class_bindings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters