diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2013-05-30 21:34:09 +0200 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2013-05-30 21:34:09 +0200 |
commit | 9684f90f8361fb314a60a387dc9ecf9bc4c3062a (patch) | |
tree | 37e595d7f4b6fdd51b18943db2be6b538ea1caea /source/LuaWindow.h | |
parent | ProtoProxy: Added a note in the documentation about the need to switch off username verification (diff) | |
download | cuberite-9684f90f8361fb314a60a387dc9ecf9bc4c3062a.tar cuberite-9684f90f8361fb314a60a387dc9ecf9bc4c3062a.tar.gz cuberite-9684f90f8361fb314a60a387dc9ecf9bc4c3062a.tar.bz2 cuberite-9684f90f8361fb314a60a387dc9ecf9bc4c3062a.tar.lz cuberite-9684f90f8361fb314a60a387dc9ecf9bc4c3062a.tar.xz cuberite-9684f90f8361fb314a60a387dc9ecf9bc4c3062a.tar.zst cuberite-9684f90f8361fb314a60a387dc9ecf9bc4c3062a.zip |
Diffstat (limited to '')
-rw-r--r-- | source/LuaWindow.h | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/source/LuaWindow.h b/source/LuaWindow.h new file mode 100644 index 000000000..c474fa1ab --- /dev/null +++ b/source/LuaWindow.h @@ -0,0 +1,78 @@ +
+// LuaWindow.h
+
+// Declares the cLuaWindow class representing a virtual window that plugins may create and open for the player
+
+
+
+
+
+#pragma once
+
+#include "UI/Window.h"
+
+
+
+
+
+// fwd: Plugin_NewLua.h
+class cPlugin_NewLua;
+
+
+
+
+
+// tolua_begin
+
+/** A window that has been created by a Lua plugin and is handled entirely by that plugin
+This object needs extra care with its lifetime management:
+- It is created by Lua, so Lua expects to garbage-collect it later
+- normal cWindow objects are deleted in their ClosedByPlayer() function if the last player closes them
+To overcome this, this object overloads the Destroy functions, which doesn't let the ClosedByPlayer()
+delete the window, but rather leaves it dangling, with only Lua having the reference to it.
+Additionally, to forbid Lua from deleting this object while it is used by players, the manual bindings for
+cPlayer:OpenWindow check if the window is of this class, and if so, make a global Lua reference for this object.
+This reference needs to be unreferenced in the Destroy() function.
+*/
+class cLuaWindow :
+ public cWindow
+{
+ typedef cWindow super;
+
+public:
+ /// Create a window of the specified type, with a slot grid of a_SlotsX * a_SlotsY size
+ cLuaWindow(cWindow::WindowType a_WindowType, int a_SlotsX, int a_SlotsY, const AString & a_Title);
+
+ virtual ~cLuaWindow();
+
+ /// Returns the internal representation of the contents that are manipulated by Lua
+ cItemGrid & GetContents(void) { return m_Contents; }
+
+ // tolua_end
+
+ /** Sets the plugin reference and the internal Lua object reference index
+ used for preventing Lua's GC to collect this class while the window is open
+ */
+ void SetLuaRef(cPlugin_NewLua * a_Plugin, int a_LuaRef);
+
+ /// Returns true if SetLuaRef() has been called
+ bool IsLuaReferenced(void) const;
+
+protected:
+ /// Contents of the non-inventory part
+ cItemGrid m_Contents;
+
+ /// The plugin that has opened the window and owns the m_LuaRef
+ cPlugin_NewLua * m_Plugin;
+
+ /// The Lua object reference, used for keeping the object alive as long as any player has the window open
+ int m_LuaRef;
+
+ // cWindow overrides:
+ virtual void Destroy(void) override;
+} ; // tolua_export
+
+
+
+
+
|