meia-lua Posted August 5, 2018 Share Posted August 5, 2018 Hello, Is there no documentation on import() as far as I remember this isn't part of Lua. Thanks. Quote Link to comment Share on other sites More sharing options...
cassius Posted August 5, 2018 Share Posted August 5, 2018 Don't you just put import"filename" ? Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
meia-lua Posted August 5, 2018 Author Share Posted August 5, 2018 Well yes but what happens if the same file is imported from multiple points in your application, For example if I have 3 scripts 'util.lua', 'math.lua' and 'main.lua'. In main.lua I import both 'ulti.lua' and 'math.lua' and in 'math.lua' I import 'util.lua'. I would have thought this sort of thing would be documented. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted August 6, 2018 Share Posted August 6, 2018 I recall that when you import a file a second time, it is ignored since you have already loaded that file. This is stored internally in a cache somewhere. Quote Link to comment Share on other sites More sharing options...
Rick Posted August 6, 2018 Share Posted August 6, 2018 It loads each time it sees an import but since you're importing the same thing (and generally it's definitions of functions and tables) it generally doesn't matter as the result is the same. If you want to avoid this you can do checks up front if something is defined or not to determine to do the rest of the script. util.lua if _UTIL_ ~= nil then return end -- define util so we only will define the util stuff once even if there are multiple imports of it _UTIL_ = {} --define util functions here Quote Link to comment Share on other sites More sharing options...
Josh Posted August 6, 2018 Share Posted August 6, 2018 import will work with the zip file system when you game is exported. Lua Include won't. It should only execute each imported file the first time it is imported by any file. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
meia-lua Posted August 7, 2018 Author Share Posted August 7, 2018 Thank you all. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.