lua指令碼載入並編譯外部的lua執行指令碼

2021-10-08 19:35:18 字數 1840 閱讀 3883

-- 封裝公用的函式檔案

-- lua列印table資料

function

luaprinttable

(t, name)

local spaceadd =

4local

function

gettablestr

(t, name, space)

local str = string.

format

("%s%s = \n"

return str

endif(

type

(t)==

"table"

)then

ngx.

print

("\n"

..gettablestr

(t, name, spaceadd)

)else

ngx.

print

(t)end

end

在test.lua中呼叫此函式:

-- 備註:修改引數跟隨輪詢檔案

local mysql = require "resty.mysql"

local db, err = mysql:

new()if

not db then

ngx.

say(

"failed to instantiate mysql: "

, err)

return

end ngx.

say(

"connected to mysql."

) db:

set_timeout

(1000

)-- 1 sec

local ok, err, errno, sqlstate = db:

connect

ifnot ok then

ngx.

say(

"failed to connect: "

, err,

": "

, errno,

" ", sqlstate)

return

end ngx.

say(

"connected to mysql."

)--查詢需要生成配置檔案的資料

local select_sql =

" select * from domain_name where status=8"

res,err,errno,sqlstate = db:

query

(select_sql)

ifnot res then

ngx.

say(

"select rows error:"

,err,

",errno:"

,errno,

",sqlstate:"

,sqlstate)

return

end-- 列印res的資料型別,輸出結果為table

ngx.

print

(type

(res)

)-- 載入並編譯外部執行指令碼

dofile

("/usr/local/openresty/nginx/lua/function.lua"

)-- 列印table資料

luaprinttable

(res,

'table')do

return

end ngx.

say(

"7777"

)-- 此句不會輸出

nginx編譯安裝支援lua指令碼

一 準備編譯環境 1 作業系統 centos7.6 2 安裝編譯所需安裝包 yum install gcc pcre pcre devel zlib zlib devel openssl openssl devel y gcc 編譯環境 pcre是乙個perl庫,包括perl相容的正規表示式庫,ng...

lua的編譯 執行

分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!lua是乙個指令碼語言,它的編譯器非常簡單。一般而言,lua在遊戲裡面使用得比較多。它可以通過類似於指令碼的形式把函式的功能序列起來,實現很多不可思議的效果。現在關於lua的資料比較少,主要有兩個文件可以介紹一下。乙個是雲風翻譯的lua手冊,另外一...

Unity toLua載入lua的流程

unity中我們要載入lua檔案呼叫的函式是 luastate類中的dofile 我們可以看到流程是 luastate dofile luastate loadfilebuffer luafileutils readfile findfile public void dofile string fi...