| 407 | // *********************************************************************** |
| 408 | |
| 409 | i32 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 | |