aboutsummaryrefslogtreecommitdiff
path: root/games/devtest/mods/basenodes/textures/default_sand.png
blob: 0ed0e4cebe7a791878fcf3c7fa2cc5e4ab7ed5d7 (plain)
ofshex dumpascii
0000 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 00 10 00 00 00 10 08 02 00 00 00 90 91 68 .PNG........IHDR...............h
0020 36 00 00 01 f1 49 44 41 54 78 01 62 7c 79 0e d0 22 55 25 38 0e 43 31 33 06 86 7b f4 bd e1 60 39 6....IDATx.b|y.."U%8.C13..{...`9
0040 58 e3 aa f0 be 1c c5 b2 c0 fe 47 08 d1 b7 39 9f cf 4c 70 4a 69 ca 95 73 3e 0e a7 c3 e1 60 8c 69 X.........G...9..LpJi..s>....`.i
0060 9a 46 4a 59 4a d9 ee 0e 22 e5 7c 59 d7 5a eb 30 0c 6d db fe ed b6 52 19 67 35 a9 19 8b d7 d7 d7 .FJYJ...".|Y.Z.0.m....R.g5......
0080 9c 33 fe 8e e3 28 84 00 ce 94 94 4a 29 a0 29 25 40 cf cf cf de 19 cc e5 72 01 e2 9c 83 7e 8c 11 .3...(.....J).)%@.......r....~..
00a0 fa d8 53 2a 65 40 19 e7 4d db 2a ad e7 69 81 ee 3c cf 21 04 10 18 ad 20 60 ab b1 7e b7 dd 01 c4 ..S*e@..M.*..i..<.!.....`..~....
00c0 59 02 be 41 70 d6 d6 52 96 38 57 06 eb 03 a4 24 94 b5 85 19 30 f1 f9 b1 f9 c0 02 d9 18 65 c8 c9 Y..Ap..R.8W....$....0........e..
00e0 f1 e3 11 5d 09 0c 64 11 1a 31 60 1d 9a 40 be be be a0 a0 24 17 b0 8b ad 19 53 8a e6 7c 98 46 90 ...]..d..1`..@.....$.....S..|.F.
0100 d7 75 45 30 c6 18 d6 70 d5 75 1d 10 6c 5b 96 45 20 ec 38 4d 11 a6 43 00 2b a6 a8 95 ae e4 5a 2b .uE0...p.u..l[.E..8M..C.+.....Z+
0120 8e 44 1e 30 d7 65 b5 ce a2 6e d0 84 f3 56 69 49 18 ba 8f 84 94 4c 02 25 45 30 21 35 f7 6d cf 25 .D.0.e...n...ViI.....L.%E0!5.m.%
0140 45 45 dd 53 8b ad 61 0d 70 c1 a6 69 d6 d6 48 2e a1 f8 f7 b7 45 d3 8d b5 e5 e6 ea 74 3a 2d f3 8c EE.S..a.p..i..H.....E......t:-..
0160 00 58 ff fe fe ce eb 0c d9 5b 4b 8c 22 b3 b5 ee 11 86 67 46 af 03 4b 60 02 1c ce 23 ad b4 e4 1a .X.......[K.".....gF..K`...#....
0180 53 b8 de c3 38 4e 31 47 a5 e4 db db 7b 2e 64 3c 8f 28 fa 4e 56 b7 17 41 19 79 df bc b7 5d c3 28 S...8N1G....{.d<.(.NV..A.y...].(
01a0 17 5d d7 a2 71 6b 4d 08 b1 94 da 7b ff 3d 8c de d3 6b eb 31 69 a9 b0 e8 9a 1e 46 48 b9 aa e1 2d .]..qkM....{.=...k.1i.....FH...-
01c0 bc 20 16 63 3c a5 05 22 80 a4 14 98 fb cd c0 d8 b5 3e 15 9e fb 67 04 00 c2 2a 86 5e af 93 4b bc ...c<..".........>...g...*.^..K.
01e0 53 76 38 1c 9d f3 f0 89 36 51 3f 08 b8 cc 6b fd 42 60 1d 63 60 b8 4b a3 0c be 11 6b b7 db 2e cb Sv8.....6Q?...k.B`.c`.K....k....
0200 ec bd 9f a6 09 89 71 1e 02 bc bc bc e0 99 e0 2d 1f 8f 47 f4 f6 1f 78 b9 70 7e 71 02 3f 8a 00 00 ......q........-..G...x.p~q.?...
0220 00 00 49 45 4e 44 ae 42 60 82 ..IEND.B`.
n143'>143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596
/*
Minetest
Copyright (C) 2022 sfan5 <sfan5@live.de>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <unordered_set>
#include <unordered_map>
#include "c_packer.h"
#include "c_internal.h"
#include "log.h"
#include "debug.h"
#include "threading/mutex_auto_lock.h"

extern "C" {
#include <lauxlib.h>
}

//
// Helpers
//

// convert negative index to absolute position on Lua stack
static inline int absidx(lua_State *L, int idx)
{
	assert(idx < 0);
	return lua_gettop(L) + idx + 1;
}

// does the type put anything into PackedInstr::sdata?
static inline bool uses_sdata(int type)
{
	switch (type) {
		case LUA_TSTRING:
		case LUA_TFUNCTION:
		case LUA_TUSERDATA:
			return true;
		default:
			return false;
	}
}

// does the type put anything into PackedInstr::<union>?
static inline bool uses_union(int type)
{
	switch (type) {
		case LUA_TNIL:
		case LUA_TSTRING:
		case LUA_TFUNCTION:
			return false;
		default:
			return true;
	}
}

static inline bool can_set_into(int ktype, int vtype)
{
	switch (ktype) {
		case LUA_TNUMBER:
			return !uses_union(vtype);
		case LUA_TSTRING:
			return !uses_sdata(vtype);
		default:
			return false;
	}
}

// is the key suitable for use with set_into?
static inline bool suitable_key(lua_State *L, int idx)
{
	if (lua_type(L, idx) == LUA_TSTRING) {
		// strings may not have a NULL byte (-> lua_setfield)
		size_t len;
		const char *str = lua_tolstring(L, idx, &len);
		return strlen(str) == len;
	} else {
		assert(lua_type(L, idx) == LUA_TNUMBER);
		// numbers must fit into an s32 and be integers (-> lua_rawseti)
		lua_Number n = lua_tonumber(L, idx);
		return std::floor(n) == n && n >= S32_MIN && n <= S32_MAX;
	}
}

namespace {
	// checks if you left any values on the stack, for debugging
	class StackChecker {
		lua_State *L;
		int top;
	public:
		StackChecker(lua_State *L) : L(L), top(lua_gettop(L)) {}
		~StackChecker() {
			assert(lua_gettop(L) >= top);
			if (lua_gettop(L) > top) {
				rawstream << "Lua stack not cleaned up: "
					<< lua_gettop(L) << " != " << top
					<< " (false-positive if exception thrown)" << std::endl;
			}
		}
	};

	// Since an std::vector may reallocate, this is the only safe way to keep
	// a reference to a particular element.
	template <typename T>
	class VectorRef {
		std::vector<T> *vec;
		size_t idx;
		VectorRef(std::vector<T> *vec, size_t idx) : vec(vec), idx(idx) {}
	public:
		constexpr VectorRef() : vec(nullptr), idx(0) {}
		static VectorRef<T> front(std::vector<T> &vec) {
			return VectorRef(&vec, 0);
		}
		static VectorRef<T> back(std::vector<T> &vec) {
			return VectorRef(&vec, vec.size() - 1);
		}
		T &operator*() { return (*vec)[idx]; }
		T *operator->() { return &(*vec)[idx]; }
		operator bool() const { return vec != nullptr; }
	};

	struct Packer {
		PackInFunc fin;
		PackOutFunc fout;
	};

	typedef std::pair<std::string, Packer> PackerTuple;
}

static inline auto emplace(PackedValue &pv, s16 type)
{
	pv.i.emplace_back();
	auto ref = VectorRef<PackedInstr>::back(pv.i);
	ref->type = type;
	// Initialize fields that may be left untouched