Skip to content

Latest commit

 

History

History
99 lines (68 loc) · 2.1 KB

class_bindings.rst

File metadata and controls

99 lines (68 loc) · 2.1 KB

Class Bindings

C++ classes binding use /api_reference/metatable.

A quick example

Exposing classes to Lua

Usage in 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:

Pointer assign

You need managing object lifetime by yourself.

broken code example:

Smartpointers

If you think troublesome for managing lifetime, can use shared_ptr.

Note

If KAGUYA_USE_CPP11<preprocessor-use-cpp11> is 0, std::shared_ptr(and std::tr1::shared_ptr) is unrecognized, and vice versa. see /api_reference/standard