cortav  strutils.c at trunk

File bind/strutils.c artifact 9bbacd41f1 on branch trunk


#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));