dopezt Posted December 23, 2015 Share Posted December 23, 2015 I've just started diving into the code of Don't Stave and I'm trying to familiarize myself before I begin doing anything. I've never done any lua coding before so I'm learning as I go. I've tried googling what this global("foo") is to no avail. I've also tried looking through the don't starve code base and can't find where this is declared. Any sort of help would be welcome. Thanks! Link to comment https://forums.kleientertainment.com/forums/topic/61264-what-is-this-globalfoo-function/ Share on other sites More sharing options...
ZupaleX Posted December 24, 2015 Share Posted December 24, 2015 Could you be more precise on your question because I have no idea what you are actually asking Link to comment https://forums.kleientertainment.com/forums/topic/61264-what-is-this-globalfoo-function/#findComment-701570 Share on other sites More sharing options...
Arkathorn Posted December 24, 2015 Share Posted December 24, 2015 This question is concerning Don't Starve Together, not Don't Starve. The correct forum can be found here. In regards to your question:I don't know specifically what 'foo' is used for, but the 'global' function declares global variables. Normally in Lua global variables can be declared by assignment, but in Don't Starve the global table has been modified to require this function to be called first. In DST, this likely declares it only for the local instance, not for other networked instances. Link to comment https://forums.kleientertainment.com/forums/topic/61264-what-is-this-globalfoo-function/#findComment-701617 Share on other sites More sharing options...
ZupaleX Posted December 24, 2015 Share Posted December 24, 2015 I don't understand why you concluded it's for DST. There is the use of global() function in DS codes as well. Link to comment https://forums.kleientertainment.com/forums/topic/61264-what-is-this-globalfoo-function/#findComment-701679 Share on other sites More sharing options...
Arkathorn Posted December 24, 2015 Share Posted December 24, 2015 The string "foo" does not occur anywhere in the DS code, nor in either of the DLCs. I remember seeing, during my brief foray into the DST code, the statement he is referring to. Link to comment https://forums.kleientertainment.com/forums/topic/61264-what-is-this-globalfoo-function/#findComment-701756 Share on other sites More sharing options...
ZupaleX Posted December 24, 2015 Share Posted December 24, 2015 foo doesn't appear anywhere as a matter of fact, not even in DST. Thus my first post.This is usually used in the tutorial or explanations as a placeholder (like the first element will be called "foo" and the second "bar")... Link to comment https://forums.kleientertainment.com/forums/topic/61264-what-is-this-globalfoo-function/#findComment-701784 Share on other sites More sharing options...
dopezt Posted December 25, 2015 Author Share Posted December 25, 2015 This question is concerning Don't Starve Together, not Don't Starve. The correct forum can be found here. In regards to your question:I don't know specifically what 'foo' is used for, but the 'global' function declares global variables. Normally in Lua global variables can be declared by assignment, but in Don't Starve the global table has been modified to require this function to be called first. In DST, this likely declares it only for the local instance, not for other networked instances. foo is actually just a placeholder name. Do you know where specifically in the code this global("") function is defined? I couldn't find it anywhere. Link to comment https://forums.kleientertainment.com/forums/topic/61264-what-is-this-globalfoo-function/#findComment-701927 Share on other sites More sharing options...
dopezt Posted December 25, 2015 Author Share Posted December 25, 2015 Could you be more precise on your question because I have no idea what you are actually asking There are calls to global("foo") throughout the code and I want to know what it does. Or actually better I want to know where it is defined if you have any idea. Link to comment https://forums.kleientertainment.com/forums/topic/61264-what-is-this-globalfoo-function/#findComment-701928 Share on other sites More sharing options...
ZupaleX Posted December 25, 2015 Share Posted December 25, 2015 Why is it so important to know where the global() function is defined? What do you want to do with it? (otherwise it's in strict.lua but it won't help you at all). About what it does, basically what Arkathorn said. Link to comment https://forums.kleientertainment.com/forums/topic/61264-what-is-this-globalfoo-function/#findComment-701972 Share on other sites More sharing options...
dopezt Posted December 25, 2015 Author Share Posted December 25, 2015 Why is it so important to know where the global() function is defined? What do you want to do with it? (otherwise it's in strict.lua but it won't help you at all). About what it does, basically what Arkathorn said. This is actually my first time working with lua so I want to learn as much as I can. I especially want to learn the framework because that seems particularly interesting. Thanks! Link to comment https://forums.kleientertainment.com/forums/topic/61264-what-is-this-globalfoo-function/#findComment-701977 Share on other sites More sharing options...
Arkathorn Posted December 25, 2015 Share Posted December 25, 2015 This is actually my first time working with lua so I want to learn as much as I can. I especially want to learn the framework because that seems particularly interesting. Thanks!The way the system with the 'global' function works is by overriding the '__index' function of the metatable of the global table. The global table is the generic overarching table, where non-local fields are declared. In 'modmain.lua' and 'modworldgenmain.lua' it is referenced with 'GLOBAL' (due to those files being run in a special environment, achieved with 'setfenv'). Metatables are special tables that can be used to add special functionality to other tables. 'getmetatable(t)' returns the metatable of 't' (if any), and 'setmetatable(t,mt)' sets 'mt' as the metatable of 't'. The most common (as far as I can tell) use of metatables is the '__index' function. When a nil field is referenced in a table, it will call it's metatable's '__index' function, if there is one (The first argument is the table, the second the key value). The return value of the function will be returned to the accessor. The '__index' function can be bypassed by using 'rawget(t,k)'. Link to comment https://forums.kleientertainment.com/forums/topic/61264-what-is-this-globalfoo-function/#findComment-702020 Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now