예제 #1
0
END_NATIVE_FUNCTION
AVES_API BEGIN_NATIVE_FUNCTION(aves_StringBuffer_set_item)
{
	Aves *aves = Aves::Get(thread);

	StringBuffer *buf = THISV.Get<StringBuffer>();
	CHECKED(IntFromValue(thread, args + 1));
	if (args[2].type != aves->aves.Char)
	{
		VM_PushString(thread, strings::value); // paramName
		return VM_ThrowErrorOfType(thread, aves->aves.ArgumentTypeError, 1);
	}

	if (args[1].v.integer < 0 || args[1].v.integer >= buf->GetLength())
	{
		VM_PushString(thread, strings::index); // paramName
		return VM_ThrowErrorOfType(thread, aves->aves.ArgumentRangeError, 1);
	}
	if (args[2].v.uinteger > 0xFFFF)
	{
		VM_PushString(thread, strings::value);
		return VM_ThrowErrorOfType(thread, aves->aves.ArgumentRangeError, 1);
	}

	size_t index = (size_t)args[1].v.integer;
	buf->GetDataPointer()[index] = (ovchar_t)args[2].v.uinteger;
}
예제 #2
0
AVES_API NATIVE_FUNCTION(aves_StringBuffer_toStringSubstring)
{
	// toStringSubstr(start is Int, count is Int)
	// The public-facing method range-checks the values.

	StringBuffer *buf = THISV.Get<StringBuffer>();
	size_t start = (size_t)args[1].v.integer;
	size_t count = (size_t)args[2].v.integer;

	String *result = GC_ConstructString(thread, count, buf->GetDataPointer() + start);
	if (!result)
		return VM_ThrowMemoryError(thread);
	VM_PushString(thread, result);
	RETURN_SUCCESS;
}
예제 #3
0
AVES_API NATIVE_FUNCTION(aves_StringBuffer_appendSubstringFromBuffer)
{
	// appendSubstrFromBuffer(sb: StringBuffer, index: Int, count: Int)
	// The public-facing method also range-checks the values

	StringBuffer *dest = THISV.Get<StringBuffer>();
	StringBuffer *src = args[1].Get<StringBuffer>();
	size_t index = (size_t)args[2].v.integer;
	size_t count = (size_t)args[3].v.integer;

	if (!dest->Append(count, src->GetDataPointer() + index))
		return VM_ThrowMemoryError(thread);

	VM_Push(thread, THISP);
	RETURN_SUCCESS;
}