mIRC scripting like string token manipulation in Lua
You don't need to use tostring inside string.match or other methods provided by string meta-table.
I'd suggest allowing users to pass the character as well as ASCII-code for the separator. This is of course, you own choice and nothing needs to be done in the code to enforce this.
The following loop:

for i = 1, #tokens do
    if (i == n) then result = tokens[i] end
end


is entirely useless and can be replaced with result = tokens[n].
I do not understand your reasons behind the following conversion:

w = tonumber(w) or tostring(w)


w will be type string by default.
You can use table.concat effectively; instead of creating string buffers.
Instead of writing long winded if-else blocks, put the smaller blocks forward and return results as soon as you arrive at one.
In lua, you do not necessarily need to put the if-conditions inside parentheses.
What does a negative range imply? I tested your function with gettok(text, -3, 46, -2) expecting cherry.grape as output, instead; I received banana.cherry.
For your start and stop values, use math.max and math.min.


The rewritten code follows. Please note that I've used my own convention of variable naming.

local function Tokenize( sChar, sInput )
    local tReturn = {}
    for sWord in string.gmatch( sInput, "[^"..sChar.."]+" ) do
        table.insert( tReturn, tonumber(sWord) or sWord )
    end
    return tReturn
end

local function GetTok( sInput, iPosition, Separator, iRange )
    local Separator = string.format( '%c', Separator )
    local tTokens = Tokenize( Separator, sInput )
    if iPosition == 0 then
        return sInput
    end
    local iStart, iStop = ( iPosition &gt; 0 ) and iPosition or ( #tTokens + iPosition + 1 )
    if not iRange or iPosition == iRange then
        return tTokens[ iStart ]
    end
    if iRange &gt; 0 then
        iStop = iRange
    elseif iRange == 0 or ( iStart + iRange ) &gt; #tTokens then
        iStop = #tTokens
    else
        iStop = iStart + iRange + 1
    end
    if iStart == iStop then
        return tTokens[ iStart ]
    end
    if iStart &gt; iStop then
        iStart, iStop = iStop, iStart
    end
    return table.concat( tTokens, Separator, iStart, iStop )
end