Need help with lua_missions
Posted: Sun Apr 26, 2015 4:38 pm
Hi everyone!
So first a disclaimer - I'm super new to coding. Lua is the first language I've ever tried to learn. However, a lot of the tutorials and posts that you guys have on the forum have been super helpful - especially the ones from Kikito.
I just recently finished *almost* all of the lua_missions that he has up in Github, and I have a few questions about them:
1. I don't know any regular expressions, so I skipped the second half of patterns.lua. Is there a good place to learn them? Do I need to know them right away, or should I just wait and learn them if I need? What are they used for?
2. I'm really thrown by metatables. In particular, I don't understand why in lines 66 and 75 of indices.lua, t2.x returns nil. It was just set to equal 1. That makes it seem like tables that have been associated with metatables can't be directly altered. Is that only the case when you're using the __newindex metamethod? Why?
3. I'm completely lost on exercise.lua. First, I don't understand why we're trying to use a metamethod on strings instead of tables, when the previous lesson was all about using them on tables. Do they work on strings? How do you set them up to work with strings? Second, it seems like you should be able to solve this with a simple function. For the first set, why wouldn't you just use this sort of thing:
The ends_with function would be really similar, just using #input_string to count backwards. These don't actually work, so I assume I'm approaching it wrong, since the hint is to use a metatable. Again, I'm sorry if these questions are silly. I'm learning a TON, but I'm clearly still very much a beginner.
Thanks!
PS - @Mods - I'm not sure if this is the right place to post about this, but it's where Kikito posted when he announced lua_missions, so I figured it was a good place to start. Also you people seem very friendly!
So first a disclaimer - I'm super new to coding. Lua is the first language I've ever tried to learn. However, a lot of the tutorials and posts that you guys have on the forum have been super helpful - especially the ones from Kikito.
I just recently finished *almost* all of the lua_missions that he has up in Github, and I have a few questions about them:
1. I don't know any regular expressions, so I skipped the second half of patterns.lua. Is there a good place to learn them? Do I need to know them right away, or should I just wait and learn them if I need? What are they used for?
2. I'm really thrown by metatables. In particular, I don't understand why in lines 66 and 75 of indices.lua, t2.x returns nil. It was just set to equal 1. That makes it seem like tables that have been associated with metatables can't be directly altered. Is that only the case when you're using the __newindex metamethod? Why?
3. I'm completely lost on exercise.lua. First, I don't understand why we're trying to use a metamethod on strings instead of tables, when the previous lesson was all about using them on tables. Do they work on strings? How do you set them up to work with strings? Second, it seems like you should be able to solve this with a simple function. For the first set, why wouldn't you just use this sort of thing:
Code: Select all
local function starts_with(input_string, snippet)
return input_string:sub(1, #snippet) == snippet
end
Thanks!
PS - @Mods - I'm not sure if this is the right place to post about this, but it's where Kikito posted when he announced lua_missions, so I figured it was a good place to start. Also you people seem very friendly!