1
votes

I am using Lua code for my small project work using Explorer to interact with the esp8266 module.

I have encountered a problem that the " dofile " and "require " module are not opening scripts which are in another location.

  1. I used to this code : dofile("ds18b20.lua")

    output:

dofile("ds18b20.lua")
cannot open ds18b20.lua

  1. I also used: require("ds18b20")

    output:

require("ds18b20") stdin:1: module 'ds18b20' not found:
no field package.preload['ds18b20']
no file 'ds18b20.lc'
no file 'ds18b20.lua'

Could any one give me solution for this issues?

Thank you

2
Why are you tagging java and c? They have nothing to do with your question. - Joe C
your computer is just a stupid machine. if you don't tell it where to exactly find that file or at least where to look for it, it won't find it and blame you. follow fonfonx advice or add the path to the LUA_PATH environment variable. print(package.path) to see which folders Lua will search for a required file. - Piglet

2 Answers

0
votes

If the scripts are not in the same folder as your current script you can use dofile with the path of your script: dofile("path/to/your/script.lua")

If you want to use require one solution is to add the folder that contains your script to the package path:

package.path = package.path .. ";full/path/to/folder/?.lua"
require "script"
0
votes

To specify place of script for require you can use something like this:

require 'path.to.lib.libname.submodule'