Since it is not possible to put all the code in a file in programming, it is certain that some of the code will be open, so it is not difficult to make a file call in those high-level languages such as c++,c#. So in Lua,
These can be achieved as well. The Require function is used primarily. Here is the code to tell you.
The file being called Berequired.lua
--Private Functions
local function myprivatefunction ()
print ("This is a private function!")
End
--common interface
function vprint ()
myprivatefunction ()
print ("This was a public function!")
Print ("This is a required package!")
End
Vprint ()
--Identify the class name to create a class
complex = {Vprint = Vprint}
Calling files from other files Main.lua
Package.path = Package.path. ";?. Lua " //template-style path where the local
Requiredpackage = require (" berequired ") is obtained by the Require function, and this line is required for
print (Package.path)
Print ("\ n")
print (requiredpackage)
function vprint ()
print ("Main print!")
End
Vprint ()
local Requirecomplex = {} //Declare an object
Requirecomplex = Complex //Create the object
Requirecomplex. Vprint ()
Output results