| 438 | // *********************************************************************** |
| 439 | |
| 440 | i32 ToString(lua_State* L) { |
| 441 | UserData* pUserData = (UserData*)luaL_checkudata(L, 1, "UserData"); |
| 442 | |
| 443 | StringBuilder builder(g_pArenaFrame); |
| 444 | |
| 445 | switch(pUserData->type) { |
| 446 | case Type::Float32: builder.Append("userdata(\"f32\""); break; |
| 447 | case Type::Int32: builder.Append("userdata(\"i32\""); break; |
| 448 | case Type::Int16: builder.Append("userdata(\"i16\""); break; |
| 449 | case Type::Uint8: builder.Append("userdata(\"u8\"");; break; |
| 450 | } |
| 451 | builder.AppendFormat(",%i,%i,\"", pUserData->width, pUserData->height); |
| 452 | switch(pUserData->type) { |
| 453 | case Type::Float32: { |
| 454 | f32* pFloats = (f32*)pUserData->pData; |
| 455 | for (int i = 0; i < pUserData->width*pUserData->height; i++) { |
| 456 | if (i+1 < pUserData->width*pUserData->height) |
| 457 | builder.AppendFormat("%.9g,", pFloats[i]); |
| 458 | else |
| 459 | builder.AppendFormat("%.9g", pFloats[i]); |
| 460 | } |
| 461 | break; |
| 462 | } |
| 463 | case Type::Int32: { |
| 464 | // 8 hex digits |
| 465 | i32* pInts = (i32*)pUserData->pData; |
| 466 | for (int i = 0; i < pUserData->width*pUserData->height; i++) |
| 467 | builder.AppendFormat("%08x", pInts[i]); |
| 468 | break; |
| 469 | } |
| 470 | case Type::Int16: { |
| 471 | // 4 hex digits |
| 472 | i16* pInts = (i16*)pUserData->pData; |
| 473 | for (int i = 0; i < pUserData->width*pUserData->height; i++) |
| 474 | builder.AppendFormat("%04x", pInts[i]); |
| 475 | break; |
| 476 | } |
| 477 | case Type::Uint8: { |
| 478 | // two hex digits == 1 byte |
| 479 | u8* pInts = (u8*)pUserData->pData; |
| 480 | for (int i = 0; i < pUserData->width*pUserData->height; i++) |
| 481 | builder.AppendFormat("%02x", pInts[i]); |
| 482 | break; |
| 483 | } |
| 484 | } |
| 485 | builder.Append("\")"); |
| 486 | |
| 487 | String result = builder.CreateString(g_pArenaFrame); |
| 488 | lua_pushstring(L, result.pData); |
| 489 | return 1; |
| 490 | } |
| 491 | |
| 492 | // *********************************************************************** |
| 493 |
nothing calls this directly
no outgoing calls
no test coverage detected