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

Function NewIndex

source/userdata.cpp:409–436  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

407// ***********************************************************************
408
409i32 NewIndex(lua_State* L) {
410 // first we have the userdata
411 UserData* pUserData = (UserData*)luaL_checkudata(L, 1, "UserData");
412
413 if (lua_isnumber(L, 2)) {
414 SetImpl(L, pUserData, lua_tointeger(L, 2), 3);
415 }
416
417 u64 len;
418 const char* str = luaL_checklstring(L, 2, &len);
419
420 i32 index = -1;
421 if (strcmp(str, "x") == 0) { index = 0; }
422 else if (strcmp(str, "y") == 0) { index = 1; }
423 else if (strcmp(str, "z") == 0) { index = 2; }
424 else if (strcmp(str, "w") == 0) { index = 3; }
425
426 if (index >= 0) {
427 SetImpl(L, pUserData, index, 3);
428 }
429 else {
430 // standard indexing behaviour
431 luaL_getmetatable(L, "UserData");
432 lua_setfield(L, -1, str);
433 return 1;
434 }
435 return 0;
436}
437
438// ***********************************************************************
439

Callers

nothing calls this directly

Calls 1

SetImplFunction · 0.85

Tested by

no test coverage detected