MCPcopy Create free account
hub / github.com/DavidColson/Polybox / Index

Function Index

source/userdata.cpp:378–405  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

376// ***********************************************************************
377
378i32 Index(lua_State* L) {
379 // first we have the userdata
380 UserData* pUserData = (UserData*)luaL_checkudata(L, 1, "UserData");
381
382 // if key is number it's an array index read, otherwise it's text
383 if (lua_isnumber(L, 2)) {
384 return GetImpl(L, pUserData, lua_tointeger(L, 2), 1);
385 }
386
387 u64 len;
388 const char* str = luaL_checklstring(L, 2, &len);
389
390 i32 index = -1;
391 if (strcmp(str, "x") == 0 || strcmp(str, "r") == 0) { index = 0; }
392 else if (strcmp(str, "y") == 0 || strcmp(str, "g") == 0) { index = 1; }
393 else if (strcmp(str, "z") == 0 || strcmp(str, "b") == 0) { index = 2; }
394 else if (strcmp(str, "w") == 0 || strcmp(str, "a") == 0) { index = 3; }
395
396 if (index >= 0) {
397 return GetImpl(L, pUserData, index, 1);
398 }
399 else {
400 // standard indexing behaviour
401 luaL_getmetatable(L, "UserData");
402 lua_getfield(L, -1, str);
403 return 1;
404 }
405}
406
407// ***********************************************************************
408

Callers

nothing calls this directly

Calls 1

GetImplFunction · 0.85

Tested by

no test coverage detected