cortav  Artifact [9bbacd41f1]

Artifact 9bbacd41f1c81b2195f18299a42fdb1f787df671138a4cd6b253e2bb2a7f7118:


#include "bind.h"

_luafn(rangematch) {
	luaL_checkstring(l, 1);
	luaL_checknumber(l, 2);
	luaL_checkstring(l, 3);

	size_t strl = 0, matl = 0, start = lua_tointeger(l, 2)-1;
	const char* str = lua_tolstring(l, 1, &strl);
	const char* mat = lua_tolstring(l, 3, &matl);
	size_t to;
	if (start > strl || (to = start + matl) > strl) {
		_luaret_bool(false);
	}
	for (size_t i = start; i<to; ++i) {
		if (str[i] != mat[i - start]) _luaret_bool(false);
	}
	_luaret_bool(true);
}

_luaAPI(strutils, _export(rangematch));