_strToCPP

convert a Javascript-string to a zero terminated C++ String

Requires

import {_strFromCPP, _strToCPP} from "./tt/ttWASM.js";

Definition

function _strToCPP(jsStr)

Description

Javascript strings are same as almost everything else Objects. However a C++ string is an array of characters ending on character-code 0. _strToCPP converts a Javascript String to a C++ zero terminated string

Parameters

jsStr: A Javascript String.

Return Value

char*

Remarks

-

Example: toLower Function in C++

main.js:

import {_wasmInitA, _strFromCPP, _strToCPP} from "./tt/ttWASM.js";
import {_newTag, _render} from "./tt/ttHTML.js";
import wasm from "./web.wasm";

async function main()
{
	const originalString = "Hello from Javascript!";
	var str;
	const wasmInstance = await _wasmInitA(wasm, {}, null);
	str = _strFromCPP(wasmInstance.exports.toLower(_strToCPP(originalString)));
	_render(<h1>Javascript String:"{originalString}", C++ toLower Function: "{str}"</h1>);
}

main();

cppExample.cpp:

#include "tiktag.h"

_export char* toLower (char* strIn)
{
	int idx = 0;
	while (strIn[idx] != 0)
	{
		if (strIn[idx] >= 'A' && strIn[idx] <= 'Z')
			strIn[idx] += 0x20;
		idx++;
	}
	return (strIn);
}

Output:

See Also

_wasmInit_strFromCPP