欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

lua_cjson

程序员文章站 2022-05-18 11:02:27
...

今天看 lua 的具体语言,表示和 python 好像,其实语言大部分都很像, 我喜欢一个一个的编译走,最起码在开始的一段时间自己还不熟悉的时候 我今天看了 lua 的 function,表示他里面有我喜欢的功能 nginx 的 lua lua_code_cache 默认是开启的,每次修改 lua 脚本文

今天看 lua 的具体语言,表示和 python 好像,其实语言大部分都很像, 我喜欢一个一个的编译走,最起码在开始的一段时间自己还不熟悉的时候

我今天看了 lua 的 function,表示他里面有我喜欢的功能

nginx 的 lua lua_code_cache 默认是开启的,每次修改 lua 脚本文件都需要重启 nginx,太麻烦了,我就把它关闭了

  server{
       ...
       lua_code_cache off
       .....
  }

mac 下面编译 cjson 注意

  在Mac下编译lua-cjson需要取消CJSON_LDFLAGS = -bundle -undefined dynamic_lookup的注释

function

 function test()
   return 'zhang','jun'
 end
lastname,name = test()
lasetname --->zhang
name--------->jun

这个功能是我喜欢的,但是可能也会导致不容易维护 资料连接:http://www.lua.org/pil/5.1.html

unpack

 param1,param2 = unpack{'zhang','jun','test'}
 param1-->zhang
 param2--->jun
 test is discarded

error

 我遇到今天的第二个问题,我的 lua 文件,用到 cjson,cjson.lua
     local cjson = require "cjson"                                                                                                        
    local network = {                                                                                                  
         {name = "grauna",  IP = "210.26.30.34"},                                                                      
         {name = "arraial", IP = "210.26.30.23"},                                                                      
         {name = "lua",     IP = "210.26.23.12"},                                                                      
         {name = "derain",  IP = "210.26.23.20"},                                                                      
     }                                                                                                                 
     table.sort(network, function (a,b)                                                                                
         return (a.name > b.name)                                                                                      
     end)                                                                                                              
    -- ngx.print(cjson.encode(network))                                                                                
    print(cjson.encode(network)) 
   lua cjson.lua :
             [{"IP":"210.26.23.12","name":"lua"},{"IP":"210.26.30.34","name":"grauna"},                   
          {"IP":"210.26.23.20","name":"derain"},{"IP":"210.26.30.23","name":"arraial"}]
   luajit cjson.lua :            
          error loading module 'cjson' from file '/usr/local/lib/lua/5.1/cjson.so':
         dlopen(/usr/local/lib/lua/5.1/cjson.so, 6): Symbol not found: _luaL_setfuncs

我就郁闷了,luajit,lua 运行同一个文件我这边的错误;

先说一下我解决过程中遇到的另外一个 bug

liblua.dylib

  原始连接: https://github.com/jmettraux/rufus-lua
   It's mostly about adding that rule to the src/Makefile:
   liblua.dylib: $(CORE_O) $(LIB_O)                                                                               
            $(CC) -dynamiclib -o $@ $^ $(LIBS)                                                                         
        Here's how to build the library file and deploy it:                                                            
        make                                                                                                           
        make macosx # or make linux ...                                                                                
        make -C src liblua.dylib                                                                                       
        sudo cp src/liblua.dylib /usr/local/lib/                                                                       
        sudo make macosx install  

在修改这个 makefile 的过程中我的 vim 设置的 tab 建自动转换为空格,

    set expandtab 

这个设置导致了上述修改产生了 分隔符的错误,修改为

     set noexpandtab

就可以了,回头再改回去

then bug is

     同上

另:春哥的回复速度好快,谢谢春哥百忙之中的指点.
~