Files
dusk/src/dusk/script/module/entity/moduleentitymesh.c
T
2026-04-14 16:36:50 -05:00

71 lines
1.8 KiB
C

/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "moduleentitymesh.h"
#include "assert/assert.h"
#include "entity/component/display/entitymesh.h"
void moduleEntityMesh(scriptcontext_t *ctx) {
assertNotNull(ctx, "Script context cannot be NULL");
lua_State *l = ctx->luaState;
lua_register(l, "entityMeshGetMesh", moduleEntityMeshGetMesh);
lua_register(l, "entityMeshSetMesh", moduleEntityMeshSetMesh);
}
int moduleEntityMeshGetMesh(lua_State *L) {
assertNotNull(L, "Lua state cannot be NULL");
if(!lua_isnumber(L, 1)) {
luaL_error(L, "entityMeshGetMesh: entityId must be a number");
return 0;
}
if(!lua_isnumber(L, 2)) {
luaL_error(L, "entityMeshGetMesh: componentId must be a number");
return 0;
}
entityid_t eid = (entityid_t)lua_tonumber(L, 1);
componentid_t cid = (componentid_t)lua_tonumber(L, 2);
mesh_t *mesh = entityMeshGetMesh(eid, cid);
if(mesh == NULL) {
lua_pushnil(L);
} else {
lua_pushlightuserdata(L, mesh);
}
return 1;
}
int moduleEntityMeshSetMesh(lua_State *L) {
assertNotNull(L, "Lua state cannot be NULL");
if(!lua_isnumber(L, 1)) {
luaL_error(L, "entityMeshSetMesh: entityId must be a number");
return 0;
}
if(!lua_isnumber(L, 2)) {
luaL_error(L, "entityMeshSetMesh: componentId must be a number");
return 0;
}
entityid_t eid = (entityid_t)lua_tonumber(L, 1);
componentid_t cid = (componentid_t)lua_tonumber(L, 2);
mesh_t *mesh = NULL;
if(!lua_isnil(L, 3)) {
if(!lua_isuserdata(L, 3)) {
luaL_error(L, "entityMeshSetMesh: mesh must be a userdata or nil");
return 0;
}
mesh = (mesh_t *)lua_touserdata(L, 3);
}
entityMeshSetMesh(eid, cid, mesh);
return 0;
}