This is a creation in Article, where the information may have evolved or changed.
Well, I admit I'm a little bored!
Originally, I wrote a small in C, the integration of Lua script, Lua is mainly used to configure the system, feel very good.
Recently toss a time of Golang, write code feeling, indeed better than C, so think with Golang write a crawl novel of a slightly generic crawler, basic function, found the configuration or LUA more convenient, then try to encapsulate the LUA C-API bindings, the whole half a day, Found quite tired, went to GitHub search, found a few predecessors wrote East, but feel not very satisfied, finally through Golang official website found this.
Well, Github.com/aarzilli/golua, this package is relatively complete. Trial, and C-api basically consistent, the problem is, from the configuration file inside take a thing, still and c-api like, cumbersome. Hey, then you can only wrap it yourself again. The whole 2 hours, it feels good, read the basic configuration no problem. First put it out to see, and then slowly optimize it!
File:test.lua
w = 100h = 100.2str= "Hello World" TB = {1,2,3,4,sd={n= "Twkun", p= "password"},v= "value", list={1,2,4,5,6,7,8}}
FIle:test.go
Summary:
Package Mainimport ("./luawrapper"//"Twkun/tool/luawrapper" "FMT") func main () {lua: = new (Luawrap.luawrap) Lua. Init () Lua. Dofile ("Test.lua") defer lua. Close () fmt. PRINTLN (LUA). Getinteger ("W")) Fmt. PRINTLN (LUA). GetNumber ("H")) Fmt. PRINTLN (LUA). GetData ("H"). (float64)) Fmt. PRINTLN (LUA). GetString ("str")) var tb luawrap.iluatable = Lua. GetTable ("TB") fmt. PRINTLN (TB. GetString ("V")) tf: = tb. GetTable ("SD")//TF: = tb. GetData ("SD"). (luawrap.iluatable)//ok FMT. PRINTLN (TF. GetString ("n")) Fmt. PRINTLN (TF. GetData ("n"). (string)) Fmt. PRINTLN (TB. GetTable ("SD"). GetString ("P")) FMT. PRINTLN (TB. GetTable ("SD"). GetData ("P"). (string)) N: = tb. GetSize () fmt. PRINTLN (n) for I: = 1;i<= n;i++ {fmt. PRINTLN (TB. GetIndex (i). (float64)) } FMT. Println () tf = tb. GetTable ("list") n = tf. GetSize () fmt. PRINTLN (n, "\ n") for I: = 1;i<= n;i++ {fmt. PRINTLN (TF. GetIndex (i). (float64)) }}
Test code, write casually, name that poor Ah, later to pay attention to! You'll have time to tidy up and get on GitHub sometime.
Feel good, hey, weekend Annual meeting, no language, and go to the lake, incomparable ~ ~ ~
Create by Twkun
2013-12-13