Script

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.

API

CheckCollection

Type: FUNCTION Get current gameobject’s collection handle

Notes

Parameters

Returns

CheckGOInstance

Type: FUNCTION Get current game object instance Works in both gameobjects and gui scripts

Parameters

Returns

CheckGOInstance

Type: FUNCTION Get gameobject instance The instance reference (url) at stack index “index” will be resolved to an instance.

Notes

Parameters

Returns

Examples

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;
}

dmScript::CheckBuffer

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

Returns

dmScript::CheckBufferNoError

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

Returns

dmScript::CheckBufferUnpack

Type: 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

Returns

dmScript::CheckBufferUnpackNoError

Type: 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

Returns

dmScript::IsBuffer

Type: FUNCTION Check if the value is a dmScript::LuaHBuffer

Parameters

Returns

dmScript::LuaHBuffer

Type: STRUCT Holds info about the buffer and who owns it.

Members

Examples

See examples for dmScript::PushBuffer()

dmScript::PushBuffer

Type: FUNCTION Will increase the stack by 1.

Parameters

Examples

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);

dmScript::ToBuffer

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

Returns

GetComponentFromLua

Type: FUNCTION Get component user data from a url.

Notes

Parameters

LuaBufferOwnership

Type: ENUM Buffer ownership.

Members