2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

NeosVR コンパイラ その7

Last updated at Posted at 2023-09-25

概要

NeosVRのオブジェクトを外部で生成するコンパイラを開発した。
Phoenixのapiサーバが出来たのでテストする。

期待する動作

名前で呼び出すとオブジェクトが生成される。

仕組み

"Ore"でapiサーバを叩くと、jsonが返るので、evalで実体化する。

テストコード

function make(name) {
	var endpoint1 = "http://localhost:4000/api/posts/q";
	var src = '{"post": {"body":"a", "title":"' + name + '"}}';
	var xhr = new XMLHttpRequest();
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4 && xhr.status == 200)
		{
			var oreo = JSON.parse(xhr.responseText);
			eval(name + " = " + decodeURIComponent(oreo.data.body));
		}
		else
		{
			//alert(xhr.readyState);
			//alert(xhr.status);
		}
	};
	xhr.open("POST", endpoint1, false);
	xhr.setRequestHeader('Content-Type', 'application/json');
	xhr.send(src);
}

var Ore = {};
function test() {
  make("Ore");
  alert(Ore.Object.Name.Data);
}




実行結果

成功

成果物

以上。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?