-->
Page 1 of 1

Problems with creating a library

PostPosted: Sun Aug 14, 2016 4:36 am
by Highli
Hi there,

I try to create a simple library but it did'nt work with more than 1 function.

Here is the code of the lib:

Code: Select alllocal demo_mod = {}

function demo_mod.Mult(a, b)
  return a * b
end

function demo_mod.Add(a, b)
  return a + b
end

return demo_mod


And here the testcode for using the lib:

Code: Select alldemo = require "testlib"
local result1 = demo.Mult(10, 2)
local result2 = demo.Add(10, 2)
print(result1)
print(result2)


The result of executing is:

testlibtest.lua:3: attempt to call field 'Add' (a nil value)
stack traceback:
testlibtest.lua:3: in main chunk
[C]: in function 'dofile'
stdin:1: in main chunk

If I test it with only the first function "Mult", everything's fine!

I have no idea, what the problem is.

Any suggestions?

Regards

Erik

Re: Problems with creating a library

PostPosted: Sun Aug 14, 2016 10:12 am
by devsaurus
Your code works for me if I remove the local statements for result1 and result2. Which version of the firmware are you running? I'm on NodeMCU 1.5.4.1