Lua-cjson -> require(“cjson”) successful, then errors when calling cjson.encode
来源:互联网 发布:软件项目管理课程设计 编辑:程序博客网 时间:2024/04/30 12:42
I'm trying to encode/decode JSON in Lua using CJSON. I downloaded lua-cjson using Luarocks (http://www.kyne.com.au/~mark/software/lua-cjson-manual.html).
In the Lua interpreter, I'm using an example from the cjson manual:
> local cjson = require "cjson"> value = { true, { foo = "bar" } } > json_text = cjson.encode(value)stdin:1: attempt to index a nil value (global 'cjson')stack traceback: stdin:1: in main chunk [C]: in ?
I know that cjson is being found, because if I were to do ' require "foobar" ', Lua would error. It's just not able to use the module. Any help would be appreciated.
jsonlua luarocks
add a comment
1 Answer
activeoldest votes
up vote1 down vote
Each line in an interactive session is a separate chunk. So, the local variable created in line 1 no longer exists in the next lines. Note how the error message mentions aglobal variable. Try removing local
.
转自:https://stackoverflow.com/questions/29336895/lua-cjson-requirecjson-successful-then-errors-when-calling-cjson-encode
阅读全文
0 0
- Lua-cjson -> require(“cjson”) successful, then errors when calling cjson.encode
- cJSON
- cJSON
- cJSON
- cjson
- cJSON
- cJSON
- cJSON
- lua cjson
- 编译lua-cjson
- lua cjson 解决_luaL_setfuncs
- lua cjson应用
- lua luajit 安装cjson
- lua-cjson安装
- cjson中的稀疏数组encode
- cjson中的稀疏数组encode
- 使用Lua CJSON库进行encode与decode操作
- Lua CJSON安装和使用
- pdo连接数据库
- Object Pascal 关键字
- 为了更高效的开发代码,这里列出了一些webstorm的快捷键和zencoding
- PHP之冒泡排序的优化
- Druid数据库连接池的正确姿势
- Lua-cjson -> require(“cjson”) successful, then errors when calling cjson.encode
- Zookeeper原理详解
- Java
- Android ContentProvider 知识点总结
- 287. Find the Duplicate Number
- android 2048游戏、kotlin应用、跑马灯、动画源码
- 【数据结构】红黑树——自平衡二叉搜索树
- 设计模式之工厂模式(factory pattern)
- linux 单用户模式
local
and avoid setting a global. I know it's confusing, but unfortunately due to this limitation of the interpreter, you are forced to use two different programming styles whether you're in the command line or a script. – Hisham H M Mar 30 '15 at 4:54