|
@@ -609,6 +609,30 @@ As seen above from the event handling examples, VariantMap handling has some dif
|
|
|
|
|
|
|
|
For the rest of the functions and classes, see the generated \ref LuaScriptAPI "Lua script API reference". Also, look at the Lua counterparts of the sample applications in the Bin/Data/LuaScripts directory and compare them to the C++ and AngelScript versions to familiarize yourself with how things are done on the Lua side.
|
|
For the rest of the functions and classes, see the generated \ref LuaScriptAPI "Lua script API reference". Also, look at the Lua counterparts of the sample applications in the Bin/Data/LuaScripts directory and compare them to the C++ and AngelScript versions to familiarize yourself with how things are done on the Lua side.
|
|
|
|
|
|
|
|
|
|
+\section LuaScripting_Allocation Object allocation & Lua garbage collection
|
|
|
|
|
+
|
|
|
|
|
+There are two ways to allocate a C++ object in Lua scripting, which behave differently with respect to Lua's automatic garbage collection:
|
|
|
|
|
+
|
|
|
|
|
+1) Call object's contructor:
|
|
|
|
|
+\code
|
|
|
|
|
+local context = GetContext()
|
|
|
|
|
+local scene = Scene(context)
|
|
|
|
|
+\endcode
|
|
|
|
|
+tolua++ will register this C++ object with garbage collection, and Lua will collect it eventually. Do not use this form if you will add the
|
|
|
|
|
+object to an object hierarchy that is kept alive on the C++ side with SharedPtr's, for example child scene nodes or %UI child elements.
|
|
|
|
|
+Otherwise the object will be double-deleted, resulting in a crash.
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+2) Call the new function:
|
|
|
|
|
+\code
|
|
|
|
|
+local context = GetContext()
|
|
|
|
|
+local text = Text:new(context)
|
|
|
|
|
+\endcode
|
|
|
|
|
+When using this form the object will not collected by Lua, so it is safe to pass into C++ object hierarchies.
|
|
|
|
|
+Otherwise, to prevent memory leaks it needs to be deleted manually by calling the delete function on it:
|
|
|
|
|
+\code
|
|
|
|
|
+text:delete()
|
|
|
|
|
+\endcode
|
|
|
|
|
|
|
|
\page Rendering Rendering
|
|
\page Rendering Rendering
|
|
|
|
|
|