I was wondering if there is a way to make the lua file only once and any subsequent attempts to make this lua file will lead to the creation of no-op.
I was already thinking of doing something similar to the C ++ header if if / else / endif. I am wondering if there is a standard way to implement this.
James
well, requirepretty much doing it.
require
require "file" -- runs "file.lua" require "file" -- does not run the "file" again
, , . , require ( package.path package.cpath ).
, dofile :
do local cache={} local olddofile=dofile function dofile(x) if cache[x]==nil then olddofile(x) cache[x]=true end end end
based on lhf answer, but using package, you can also do this once:
package
package.preload["something"]=dofile "/path/to/your/file.lua"
and then use:
local x=require "something"
to download the preloaded package again. but it's a little offensive ...
Source: https://habr.com/ru/post/1716721/More articles:MySQL vs PostgreSQL on Windows - c #Ссылка на DataItem родительского контроля репитера внутри пользовательского элемента управления - c#Есть ли ограничение на число DataColumns, которое я могу добавить в DataTable? - ado.netNotify background shutdown in bash - bashJBoss 4.2.2 web service soap: address - javaWhy is my exploded Python code faster? - optimizationjavax.jws.WebService.wsdlCompiling with jboss 4.2.2 - javaHow I read char from user at command line - javaHow can I read unsigned int from binary in Perl? - ioClickOnce - Security Issues - winformsAll Articles