我正在创建一种脚本语言。 当我分配一个东西时,它会分配该东西并返回地址, 然后我可以对其进行任何操作,最后将其删除。我无法控制其中的变量, 例如在我的语言中创建结构体(具有指针和布尔值以检查指针是否指向有效数据)等, 因为这会使我的语言更慢并且占用更多 RAM。
例如:(我的脚本语言很容易理解。我怀疑您不会理解它,但是我仍会添加一些注释)
MyStruct = { //Function. For create object with it use 'new' before it.
TestAliveVar=0
}
Func = { //I'll explain what exactly this function does every place it runs.
if (!exists(arg0)) //C++: ???
exit;
arg0.TestAliveVar=1
println "Still alive!";
}
var MyVar=new MyStruct(); //Returns address of the new object in the heap
//and runs on it the `MyStruct` function.
Func(MyVar); //Sets his 'TestAliveVar' to 1
//and prints 'Still Alive!' with new line
delete(MyVar); //C++: free(MyVar);
Func(MyVar); //Does nothing
问题在于如何创建您在此代码中看到的函数
exists
。
顺便提一下,我可以在此语言中运行C++代码。