🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# Lua - 下载 <https://pecl.php.net/package/lua> liblua.dll放到php所在目录,php\_lua.dll放到ext扩展目录 ``` <pre class="calibre16">``` Lua<span class="token2">:</span><span class="token2">:</span>LUA_VERSION 获取Lua版本 返回 Lua <span class="token3">5.3</span><span class="token3">.4</span> $lua <span class="token">=</span> <span class="token5">new</span> <span class="token1">Lua</span><span class="token2">(</span><span class="token2">)</span><span class="token2">;</span> $lua<span class="token">-</span><span class="token">></span><span class="token1">assign</span><span class="token2">(</span><span class="token4">"php"</span><span class="token2">,</span> <span class="token4">'字符串'</span><span class="token2">)</span><span class="token2">;</span> <span class="token6">//给传递参数</span> $lua<span class="token">-</span><span class="token">></span><span class="token1">eval</span><span class="token2">(</span><span class="token"><</span><span class="token"><</span><span class="token"><</span>EOF <span class="token1">print</span><span class="token2">(</span>php<span class="token2">)</span> <span class="token5">function</span> <span class="token1">qq</span><span class="token2">(</span>a<span class="token2">)</span> <span class="token1">print</span><span class="token2">(</span>a<span class="token2">)</span> end EOF <span class="token2">)</span><span class="token2">;</span><span class="token6">//执行语言</span> $lua<span class="token">-</span><span class="token">></span><span class="token1">call</span><span class="token2">(</span><span class="token4">"qq"</span><span class="token2">,</span><span class="token2">[</span><span class="token4">'aa'</span><span class="token2">]</span><span class="token2">)</span><span class="token2">;</span><span class="token6">//执行函数</span> $lua<span class="token">-</span><span class="token">></span><span class="token1">registerCallback</span><span class="token2">(</span><span class="token4">"echo"</span><span class="token2">,</span> <span class="token4">"dump"</span><span class="token2">)</span><span class="token2">;</span> <span class="token6">//php函数传给lua</span> $lua<span class="token">-</span><span class="token">></span><span class="token1">eval</span><span class="token2">(</span><span class="token"><</span><span class="token"><</span><span class="token"><</span>CODE <span class="token1">echo</span><span class="token2">(</span><span class="token2">{</span><span class="token3">1</span><span class="token2">,</span> <span class="token3">2</span><span class="token2">,</span> <span class="token3">3</span><span class="token2">}</span><span class="token2">)</span><span class="token2">;</span> CODE <span class="token2">)</span><span class="token2">;</span> $lua<span class="token">-</span><span class="token">></span><span class="token1">include</span><span class="token2">(</span><span class="token4">"1.lua"</span><span class="token2">)</span><span class="token2">;</span> 调用lua<span class="token2">,</span>如果不需要输出<span class="token2">,</span>在里面可以<span class="token5">return</span>返回<span class="token2">,</span>返回值多个时候是数组<span class="token2">,</span>从<span class="token3">0</span>下标开始<span class="token2">;</span>还可以返回lua数组 ``` ```