Built-in scripting functions.
Namespace: | dmScript |
Include: | #include <dmsdk/gamesys/script.h> |
ENUMS | |
---|---|
LuaBufferOwnership | buffer ownership |
STRUCTS | |
---|---|
struct dmScript::LuaHBuffer | Lua wrapper for a dmBuffer::HBuffer |
lua_State* CheckCollection(lua_State* L, int index)
Get current gameobject's collection handle
PARAMETERS
lua_State* |
L |
lua state |
int |
index |
lua-arg |
RETURNS
lua_State* |
gameobject instance |
dmGameObject::HInstance CheckGOInstance(lua_State* L)
Get current game object instance Works in both gameobjects and gui scripts
PARAMETERS
lua_State* |
L |
lua state |
RETURNS
dmGameObject::HInstance |
dmGameObject::HInstance CheckGOInstance(lua_State* L, int index)
Get gameobject instance The instance reference (url) at stack index "index" will be resolved to an instance.
PARAMETERS
lua_State* |
L |
lua state |
int |
index |
lua-arg |
RETURNS
dmGameObject::HInstance |
gameobject instance |
EXAMPLES
How to get the position of a gameobject in a script extensionstatic int get_position(lua_State* L)
{
DM_LUA_STACK_CHECK(L, 3);
dmGameObject::HInstance instance = dmScript::CheckGOInstance(L, 1);
dmVMath::Point3 position = dmGameObject::GetPosition(instance);
lua_pushnumber(L, position.getX());
lua_pushnumber(L, position.getY());
lua_pushnumber(L, position.getZ());
return 3;
}
LuaHBuffer* dmScript::CheckBuffer(lua_State* L, int index)
Retrieve a LuaHBuffer from the supplied lua state. Check if the value in the supplied index on the lua stack is a LuaHBuffer and returns it.
PARAMETERS
lua_State* |
L |
lua state |
int |
index |
Index of the value |
RETURNS
LuaHBuffer* |
pointer to dmScript::LuaHBuffer |
LuaHBuffer* dmScript::CheckBufferNoError(lua_State* L, int index)
Retrieve a LuaHBuffer from the supplied lua state. Check if the value in the supplied index on the lua stack is a LuaHBuffer and returns it.
PARAMETERS
lua_State* |
L |
lua state |
int |
index |
Index of the value |
RETURNS
LuaHBuffer* |
pointer to dmScript::LuaHBuffer or 0 if not valid |
dmBuffer::HBuffer dmScript::CheckBufferUnpack(lua_State* L, int index)
Retrieve a HBuffer from the supplied lua state Check if the value in the supplied index on the lua stack is a LuaHBuffer and it's valid, returns the HBuffer.
PARAMETERS
lua_State* |
L |
lua state |
int |
index |
Index of the value |
RETURNS
dmBuffer::HBuffer |
buffer if valid, 0 otherwise |
dmBuffer::HBuffer dmScript::CheckBufferUnpackNoError(lua_State* L, int index)
Retrieve a HBuffer from the supplied lua state Check if the value in the supplied index on the lua stack is a LuaHBuffer and it's valid, returns the HBuffer.
PARAMETERS
lua_State* |
L |
lua state |
int |
index |
Index of the value |
RETURNS
dmBuffer::HBuffer |
buffer if valid, 0 otherwise |
boolean dmScript::IsBuffer(lua_State* L, int index)
Check if the value is a dmScript::LuaHBuffer
PARAMETERS
lua_State* |
L |
lua state |
int |
index |
Index of the value |
RETURNS
boolean |
True if value at index is a LuaHBuffer |
void dmScript::PushBuffer(lua_State* L, dmScript::LuaHBuffer buffer)
Will increase the stack by 1.
PARAMETERS
lua_State* |
L |
lua state |
dmScript::LuaHBuffer |
buffer |
buffer to push |
EXAMPLES
How to push a buffer and give Lua ownership of the buffer (GC)dmScript::LuaHBuffer luabuf(buffer, dmScript::OWNER_LUA);
PushBuffer(L, luabuf);
dmScript::LuaHBuffer luabuf(buffer, dmScript::OWNER_C);
PushBuffer(L, luabuf);
LuaHBuffer* dmScript::ToBuffer(lua_State* L, int index)
Retrieve a LuaHBuffer from the supplied lua state. Check if the value in the supplied index on the lua stack is a LuaHBuffer and returns it.
PARAMETERS
lua_State* |
L |
lua state |
int |
index |
Index of the value |
RETURNS
LuaHBuffer* |
pointer to dmScript::LuaHBuffer or 0 if not valid |
void GetComponentFromLua(lua_State* L, int index, const char* component_type, dmGameObject::HComponentWorld* world, dmGameObject::HComponent* component, dmMessage::URL* url)
Get component user data from a url.
PARAMETERS
lua_State* |
L |
Lua state |
int |
index |
index to argument (a url) |
const char* |
component_type |
E.g. "factoryc". The call will fail if the found component does not have the specified extension |
dmGameObject::HComponentWorld* |
world |
The world associated owning the component. May be 0 |
dmGameObject::HComponent* |
component |
The component data associated with the url. May be 0 |
dmMessage::URL* |
url |
The resolved url. May be 0 |
TYPE
struct dmScript::LuaHBuffer
Holds info about the buffer and who owns it.
MEMBERS
|
Union |
of - m_BufferRes [type:void*] A buffer resource - m_Buffer [type:dmBuffer::HBuffer] A buffer |
dmBuffer::HBuffer |
m_Buffer |
The buffer (or resource) |
dmScript::LuaBufferOwnership |
m_Owner |
What ownership the pointer has |
Buffer ownership. - OWNER_C - m_Buffer is owned by C side, should not be destroyed when GCed - OWNER_LUA - m_Buffer is owned by Lua side, will be destroyed when GCed - OWNER_RES - m_Buffer not used, has a reference to a buffer resource instead. m_BufferRes is owned by C side, will be released when GCed
dmScript::OWNER_C |
|
dmScript::OWNER_LUA |
|
dmScript::OWNER_RES |