ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
## woo 命令行详解 > 1.直接运行一个woo文件 ```lua woo work.woo ``` > 2.使用 -r 来动态执行脚本 ```lua|woo -- 使用 `-r` 参数执行脚本(性能测试:斐波那契递归测试) woo -r " function fib(n)if n == 0 then return 0;elseif n == 1 then return 1;end return fib(n-1) + fib(n-2) end; print(fib(35))" woo -r "print(_os())" -- window/linux -- 运行中需要导入扩展包路径,使用-p参数 woo -r "_out(require('any_type'):new('hello world!'):toString());" -p ~/cwm ``` > 3.使用 -rc 或 --run_console 来启动交互命令行,支持运行多行输入 **-rc目前在windows中使用git bash命令行中运行必须加上前置命令 `winpty`,如:`winpty ./woo.exe -rc`,或者使用标准的、powershell / cmd程序,win+R键入cmd / powershell,回车即可** ```lua|woo -- 开启控制台实时输入并运行 -- woo -rc -- 或 -- woo --run_console -- 然后运行例子(直接输出结果): 1+111 >112 _md5(123) >202cb962ac59075b964b07152d234b70 _time() >1614910341 woo >--这里输出woo表-- -- (脚本前加上冒号[:])则表示运行一段脚本,且需要手写输出函数来输出结果 :local t=_time();print(_date('Y-m-d H:i:s',t)) >2021-03-05 10:16:18 -- 设置并且获取redis结果: :local redis =woo.redis:new();local r=(redis:open('127.0.0.1:6379', nil, 0));redis:exec('set', 'key','hello world!');print(redis:exec('get', 'key')) >hello world! -- 运行多行代码,使用 `:C` 或 `;;;` 来启动记录多行输入代码,使用 `:R` 或 `;;;`立即执行记录的多行代码 -- 比如可以直接输入下方未注释代码: :C local gd = woo.gd:new() local wh = 1024 gd:create(wh, wh) -- 创建一个正方形画布: 1024 X 1024 gd:setRGBA(0, 0, 0, 0.1) for i = 0, 360, 15 do gd:push() gd:rotateAbout(i, wh / 2, wh / 2) gd:drawEllipse(wh / 2, wh / 2, wh * 7 / 16, wh / 8) gd:fill() gd:pop() end -- save png file to desktop folder local save_file = _home() .. "/Desktop/out.png" local file_quality = 80 -- 可以保存为jpg --local err = gd:saveJpg(save_file, file_quality) local err = gd:savePng(save_file) print(err) _show(save_file) -- 显示保存的图片(注意:只有gui桌面才能显示图片,服务器类不能显示图片,请下载图片后自行查看) :R ``` ![](https://img.kancloud.cn/db/95/db95dd064c31969f2d1511996172ccb5_400x288.gif) ***** >4.使用管道符 `|` 来传递代码给woo执行 ```shell #unix类系统(或者windows下的git bash),请使用 echo "print(_os(true))" | woo -r #windows系统,标准控制台内不能使用 `./` 这样的相对路径, 请使用绝对路径,或把woo加入环境变量,自动安装的woo语言会自动加入环境变量 #windows powershellll : echo "print(_os(true))"|.\woo.exe -r #windows cmd: echo print(_os(true))|.\woo.exe -r ```