| 535 | // *********************************************************************** |
| 536 | |
| 537 | void ParseUserData(lua_State* L, Scan::ScanningState& scan) { |
| 538 | // we assume the userdata word has been parsed already |
| 539 | // so match ( |
| 540 | if (!Scan::Match(scan, '(')) |
| 541 | luaL_error(L, "Expected '(' to start userdata"); |
| 542 | |
| 543 | i32 userdataWidth = 1; |
| 544 | i32 userdataHeight = 1; |
| 545 | Type userdataType = Type::Int32; |
| 546 | |
| 547 | // parse an identifier to get the type |
| 548 | char* pStart = scan.pCurrent; |
| 549 | while (Scan::Peek(scan) != ',') |
| 550 | Scan::Advance(scan); |
| 551 | |
| 552 | String identifier; |
| 553 | identifier.pData = pStart; |
| 554 | identifier.length = scan.pCurrent - pStart; |
| 555 | |
| 556 | i32 typeSize = 0; |
| 557 | if (identifier == "\"f32\"") { |
| 558 | userdataType = Type::Float32; |
| 559 | typeSize = sizeof(f32); |
| 560 | } |
| 561 | else if (identifier == "\"i32\"") { |
| 562 | userdataType = Type::Int32; |
| 563 | typeSize = sizeof(i32); |
| 564 | } |
| 565 | else if (identifier == "\"i16\"") { |
| 566 | userdataType = Type::Int16; |
| 567 | typeSize = sizeof(i16); |
| 568 | } |
| 569 | else if (identifier == "\"u8\"") { |
| 570 | userdataType = Type::Uint8; |
| 571 | typeSize = sizeof(u8); |
| 572 | } |
| 573 | else { |
| 574 | luaL_error(L, "Unexpected userdata value type"); |
| 575 | } |
| 576 | |
| 577 | Scan::Advance(scan); // , |
| 578 | if (Scan::IsDigit(Scan::Advance(scan))) |
| 579 | userdataWidth = (i32)ParseNumber(scan); |
| 580 | else |
| 581 | luaL_error(L, "Expected number for width"); |
| 582 | |
| 583 | if (!Scan::Match(scan, ',')) |
| 584 | luaL_error(L, "Expected ',' between arguments"); |
| 585 | |
| 586 | if (Scan::IsDigit(Scan::Advance(scan))) |
| 587 | userdataHeight = (i32)ParseNumber(scan); |
| 588 | else |
| 589 | luaL_error(L, "Expected number for height"); |
| 590 | |
| 591 | // Actually alloc the userdata |
| 592 | UserData* pUserData = AllocUserData(L, userdataType, userdataWidth, userdataHeight); |
| 593 | |
| 594 | if (!Scan::Match(scan, ',')) |
no test coverage detected