VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
bindableLuaComponent.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2013 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 
8 
10 
11 #pragma once
12 
15 #include <luabind/detail/make_instance.hpp>
16 #include <luabind/detail/class_rep.hpp>
17 
19 
22 {
23 public:
26  DtBindableLuaComponentInterface(DtLocalObject* entity, const DtString& componentName, const DtString& componentType);
27 
30 
32  virtual void bindLuaFunctions(lua_State*) = 0;
33 
35  virtual void bindLuaGlobals(lua_State*) = 0;
36 
38  virtual void bind(DtLocalObject*, const DtString& scriptId, lua_State*);
39 
41  virtual DtString bindableName(const DtString&) const;
42 
44  virtual void cleanup(lua_State*) {};
45 
46 protected:
47  virtual bool shouldBind(lua_State*) const = 0;
48 
49 protected:
51  lua_State* myBoundForState;
53 };
54 
55 template <typename T>
57 {
58 public:
60  const DtString& componentName, const DtString& componentType) : DtBindableLuaComponentInterface(entity, componentName, componentType)
61  {
62  }
63 
64  virtual ~DtBindableLuaComponent() override {}
65 
66  virtual bool shouldBind(lua_State* L) const override
67  {
68  std::pair<luabind::detail::class_id, void*> dynamic = luabind::detail::get_dynamic_class(L,
69  luabind::get_pointer(dynamic_cast<const T*>(this)));
70 
71  luabind::detail::class_rep* cls = luabind::detail::get_pointee_class(L, dynamic_cast<const T*>(this), dynamic.first);
72 
73  return (cls == 0);
74  }
75 };
76 
80 {
81 public:
84 
86  virtual ~DtBindableLuaComponentExtension() override;
87 
90  static DtLuaScriptInterfaceExtension* create(void* usr);
91 
92  virtual void cleanup(lua_State*) override;
93 
94  virtual void clearBackingPointer(void* usr) override;
95 
96 protected:
100  virtual void bindLuaFunctions(DtLocalObject* entity, const DtString& scriptId, lua_State* L) override;
101 
102 protected:
104 };
#define DT_DLL_vrfmodel
This file is used to determine how to build.
Definition: vrfmodelDefines.h:24
DtBindableLuaComponent(DtLocalObject *entity, const DtString &componentName, const DtString &componentType)
Definition: bindableLuaComponent.h:59
DtLocalObject * myBoundEntity
Definition: bindableLuaComponent.h:50
virtual void bindLuaFunctions(DtLocalObject *, const DtString &scriptId, lua_State *)=0
Bind any methods that are part of this class to the lua_state. The object supplied is the entity that...
virtual void cleanup(lua_State *)
Clean up any state that was added to the lua state if needed for reinitialize.
Definition: bindableLuaComponent.h:44
DtString myType
Definition: bindableLuaComponent.h:52
DtBindableLuaComponentInterface * myExtension
Definition: bindableLuaComponent.h:103
Definition: bindableLuaComponent.h:56
virtual void clearBackingPointer(void *)
Called when the object that backs this extension is about to be destroyed. Implementations should nul...
Definition: luaScriptInterfaceExtension.h:58
virtual void cleanup(lua_State *)=0
Called to cleanup any state. The most important thing would be to clean up any global space...
Multiply inherit from this class to add some convenience lua functions.
Definition: bindableLuaComponent.h:21
This class will be used to bind Lua functions to allow for control of the swinging part actuator...
Definition: bindableLuaComponent.h:79
Subclass this class in order to provide extensions to the LUA interface. In order to be considered a ...
Definition: luaScriptInterfaceExtension.h:31
virtual ~DtBindableLuaComponent() override
Definition: bindableLuaComponent.h:64
lua_State * myBoundForState
Definition: bindableLuaComponent.h:51
virtual bool shouldBind(lua_State *L) const override
Definition: bindableLuaComponent.h:66
A locally simulated VRF object.
Definition: localObject.h:98

Document ID: Generated on Thu Oct 15 21:27:02 EDT 2026 from SVN revision 296421
Copyright © 2005-2026 MAK Technologies. All Rights Reserved (www.mak.com)