折言(origami-lang) 是一门创新性的融合型脚本语言,深度结合 PHP 的快速开发基因与 Go 的高效并发模型。同时还有部分 go 、ts 习惯引入。
当前未对代码分支进行任何优化,性能尚未优化。 请作为一个工具使用,请勿用于生产环境。
vm.RegisterFunction("add", func(a, b int) int { return a + b })
vm.RegisterReflectClass("User", &User{})
$user = new User(Name: "Alice")
$user->SetName("Bob")
spawn
关键字启动协程int $i = 0
和可空类型 ?string
"Hello {$name}"
和 "@{function()}"
语法like
关键字进行结构匹配函数
、输出
等function($param: type)
语法spawn
关键字启动异步协程class DB<T>
泛型语法$array->map()->filter()->reduce()
map()
, filter()
, reduce()
, flatMap()
find()
, findIndex()
, includes()
instanceof
和 like
操作符parent::
语法// 定义 Go 结构体
type Calculator struct {
Name string
}
func (c *Calculator) Add(a, b int) int {
return a + b
}
func (c *Calculator) GetName() string {
return c.Name
}
// 注册到脚本域
vm.RegisterReflectClass("Calculator", &Calculator{})
<?php
// 在脚本中使用
$calc = new Calculator(Name: "MyCalc");
echo $calc->GetName(); // 输出: MyCalc
echo $calc->Add(5, 3); // 输出: 8
?>
// 注册 Go 函数
vm.RegisterFunction("add", func(a, b int) int { return a + b })
vm.RegisterFunction("isEven", func(n int) bool { return n%2 == 0 })
<?php
// 脚本中调用
$result = add(5, 3); // 返回 8
$even = isEven(4); // 返回 true
?>
int $count = 0;
string $name = "World";
echo "Hello {$name}";
function greet(string $name): string {
return "Hello " . $name;
}
function div($obj) {
return "<div>" + $obj->body + "</div>";
}
function span($obj) {
return "<span>" + $obj->body + "</span>";
}
$html = div {
"body": span {
"body": "内容",
}
}
class Users {
public $name = "";
}
class DB<T> {
public $where = {};
public function where($key, $value) {
$this->where[$key] = $value;
return $this;
}
public function get() {
return [new T()];
}
}
$list = DB<Users>()->where("name", "张三")->get();
function fetchData($url: string): string {
// 模拟网络请求
sleep(1);
return "Data from " . $url;
}
// 启动异步协程
spawn fetchData("https://api.example.com");
echo "Main thread continues...\n";
$content = <div class="container">
<h1>{$title}</h1>
<p>This is embedded HTML</p>
</div>;
$numbers = [1, 2, 3, 4, 5];
$doubled = $numbers->map(($n) => $n * 2);
$evens = $numbers->filter(($n) => $n % 2 == 0);
函数 用户(名称) {
输出 名称;
}
用户("张三");
git clone https://github.com/php-any/origami.git
cd origami
go build -o origami .
./origami script.php
MIT 许可证
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.