| 357 | // *********************************************************************** |
| 358 | |
| 359 | i32 Get2D(lua_State* L) { |
| 360 | UserData* pUserData = (UserData*)luaL_checkudata(L, 1, "UserData"); |
| 361 | if (pUserData->height == 1) { |
| 362 | luaL_error(L, "Get2D is only valid on 2-dimensional userdatas"); |
| 363 | return 0; |
| 364 | } |
| 365 | i32 x = (i32)luaL_checkinteger(L, 2); |
| 366 | i32 y = (i32)luaL_checkinteger(L, 3); |
| 367 | i32 count = (i32)luaL_checkinteger(L, 3); |
| 368 | i32 index = pUserData->width * y + x; |
| 369 | if (index + count > pUserData->width * pUserData->height) { |
| 370 | luaL_error(L, "Out of bounds read on userdata with size (%d,%d) at index (%d,%d)", pUserData->width, pUserData->height, x, y); |
| 371 | return 0; |
| 372 | } |
| 373 | return GetImpl(L, pUserData, index, count); |
| 374 | } |
| 375 | |
| 376 | // *********************************************************************** |
| 377 | |