Namespace: dmScript
Language: C++
Type: Defold C++
File: script.h
Source: engine/gamesys/src/dmsdk/gamesys/script.h
Include: dmsdk/gamesys/script.h
Built-in scripting functions.
Type: FUNCTION Get current gameobject’s collection handle
Notes
Parameters
L (lua_State*) - lua stateindex (int) - lua-argReturns
instance (lua_State*) - gameobject instanceType: FUNCTION Get current game object instance Works in both gameobjects and gui scripts
Parameters
L (lua_State*) - lua stateReturns
instance (dmGameObject::HInstance)Type: FUNCTION Get gameobject instance The instance reference (url) at stack index “index” will be resolved to an instance.
Notes
Parameters
L (lua_State*) - lua stateindex (int) - lua-argReturns
instance (dmGameObject::HInstance) - gameobject instanceExamples
How to get the position of a gameobject in a script extension
static 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;
}
Type: FUNCTION 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.
Notes
Parameters
L (lua_State*) - lua stateindex (int) - Index of the valueReturns
buffer (LuaHBuffer*) - pointer to dmScript::LuaHBufferType: FUNCTION 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.
Notes
Parameters
L (lua_State*) - lua stateindex (int) - Index of the valueReturns
buffer (LuaHBuffer*) - pointer to dmScript::LuaHBuffer or 0 if not validType: FUNCTION 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.
Notes
Parameters
L (lua_State*) - lua stateindex (int) - Index of the valueReturns
buffer (dmBuffer::HBuffer) - buffer if valid, 0 otherwiseType: FUNCTION 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.
Notes
Parameters
L (lua_State*) - lua stateindex (int) - Index of the valueReturns
buffer (dmBuffer::HBuffer) - buffer if valid, 0 otherwiseType: FUNCTION Check if the value is a dmScript::LuaHBuffer
Parameters
L (lua_State*) - lua stateindex (int) - Index of the valueReturns
boolean (boolean) - True if value at index is a LuaHBufferType: STRUCT Holds info about the buffer and who owns it.
Members
Union - of
m_Buffer (dmBuffer::HBuffer) - The buffer (or resource)m_Owner (dmScript::LuaBufferOwnership) - What ownership the pointer hasExamples
See examples for dmScript::PushBuffer()
Type: FUNCTION Will increase the stack by 1.
Parameters
L (lua_State*) - lua statebuffer (dmScript::LuaHBuffer) - buffer to pushExamples
How to push a buffer and give Lua ownership of the buffer (GC)
dmScript::LuaHBuffer luabuf(buffer, dmScript::OWNER_LUA);
PushBuffer(L, luabuf);
How to push a buffer and keep ownership in C++
dmScript::LuaHBuffer luabuf(buffer, dmScript::OWNER_C);
PushBuffer(L, luabuf);
Type: FUNCTION 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.
Notes
Parameters
L (lua_State*) - lua stateindex (int) - Index of the valueReturns
buffer (LuaHBuffer*) - pointer to dmScript::LuaHBuffer or 0 if not validType: FUNCTION Get component user data from a url.
Notes
Parameters
L (lua_State*) - Lua stateindex (int) - index to argument (a url)component_type (const char*) - E.g. “factoryc”. The call will fail if the found component does not have the specified extensionworld (dmGameObject::HComponentWorld*) - The world associated owning the component. May be 0component (dmGameObject::HComponent*) - The component data associated with the url. May be 0url (dmMessage::URL*) - The resolved url. May be 0Type: ENUM Buffer ownership.
Members
dmScript::OWNER_CdmScript::OWNER_LUAdmScript::OWNER_RES