local calc
=
require
"
calc
"
print(calc.add(
20
,
40
))
print(calc.sub(
20
,
40
))
cc
-
g
-
D_DEBUG
-
DDEBUG
-
Wall
-
I.
/
skynet
/
3rd
/
lua
-
fPIC
--
shared lcalc.c
-
o calc.so
lua calc.lua
lua: error loading module 'calc' from file './calc.lua':
./calc.lua:3: too many C levels (limit is 200) in main function near '20'
stack traceback:
[C]: in ?
[C]: in function 'require'
./calc.lua:1: in main chunk
[C]: in function 'require'
./calc.lua:1: in main chunk
[C]: in function 'require'
./calc.lua:1: in main chunk
[C]: in function 'require'
./calc.lua:1: in main chunk
[C]: in function 'require'
...
[C]: in function 'require'
./calc.lua:1: in main chunk
[C]: in function 'require'
./calc.lua:1: in main chunk
[C]: in function 'require'
./calc.lua:1: in main chunk
[C]: in function 'require'
./calc.lua:1: in main chunk
[C]: in function 'require'
calc.lua:1: in main chunk
[C]: in ?
一开始以为是 require 路径的问题,但一直忽略了 too many C levels 这个错
当 require calc 时, 它会一直死循环在加载 calc.lua
luaopen_calc() 改名 或 calc.lua 其中一个改名即可解决
当初,在skynet 见到 luaopen_skynet_c() & require "skynet.c" 很奇怪,为什么Lua的作者会这样设计语言
现在想起来,好像有那么一点道理.