How to share code between script-scope things? #3926
Answered
by
waruqi
davidchisnall
asked this question in
Q&A
-
[ Slightly simplified version of my problem: ] I have two targets in the same file that both run some code in an |
Beta Was this translation helpful? Give feedback.
Answered by
waruqi
Jul 5, 2023
Replies: 1 comment 2 replies
-
use memcachetarget("foo")
on_load(function (target)
import("core.cache.memcache")
memcache.set("cachename", "key", "value")
end)
target("bar")
on_load(function (target)
import("core.cache.memcache")
local memcache.get("cachename", "key")
end) use target:data()target("foo")
on_load(function (target)
target:data_set("key", "value")
end)
target("bar")
on_load(function (target)
import("core.project.project")
local foo = project.targets()["foo"]
local value = foo:data("key")
end) use single script filetarget("foo")
on_load(function (target)
import("load_module").load_foo(target)
end)
target("bar")
on_load(function (target)
import("load_module").load_bar(target)
end) load_module.lua function load_foo(target)
_g.key = "value"
end
function load_bar(target)
local value = _g.key
end you can also use memcache in this file or use global lua variable |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
davidchisnall
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
use memcache
use target:data()
use single script file