lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

2011/3/10 Jayanth Acharya <>:
> Probably as a result of adopting a leap-frogging (instead of a thorough)
> approach to learning Lua, am not quite able to figure out what this segment
> of code does/means, and a google search didn't yeild much.
> local struct = require(_NAME:match("^[^%.]+"))
> local name = (...):gsub('%.[^%.]+$', '')
> This is from the vstruct basic.lua example. What does the _NAME:match() do ?

This is the same as string.match(_NAME, "^[^%.]+"), which assumes the
_NAME variable (global unless defined as local above in the script) is
a string, and it returns everything up to the first dot character in
that string. For example if _NAME is "", then struct would
be "foo".

> What does "(...):gsub(pattern...)" do ?

... at the global scope refers to the parameters passed to the current
script. If this is a module, "require" will pass the module name as
only parameter. This is the same as :

local modname = ...
local name = string.gsub(modname, '%.[^%.]+$', '')

And that would remove the last part of a dot-delimited sequence of
sub-strings. For example if modname=="", then name would be