Jump to content

import()


meia-lua
 Share

Recommended Posts

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. 

 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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.

  • Thanks 1

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

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...