Difference between revisions of "Module:String"

From hyperspacewiki
Jump to: navigation, search
(s1 = "Hello, world")
Line 1: Line 1:
 
local str = {}
 
local str = {}
  
function str:len( frame )
+
function str.len( frame )
 
     local new_args = str._getParameters( frame.args, {'s'} );
 
     local new_args = str._getParameters( frame.args, {'s'} );
 
     local s = new_args['s'] or '';
 
     local s = new_args['s'] or '';
Line 7: Line 7:
 
     return mw.ustring.len( s )
 
     return mw.ustring.len( s )
 
end
 
end
 +
 +
return str

Revision as of 04:28, 19 December 2018

String Module

The original source code for this module was taken from the Wikipedia String Module but had to be re-written because the Wikipedia code used an overly general method for getting the function parameters that resulted in a null reference error. I simplified the argument referencing which solved the error.

Functions

Length

Returns the length of the passed-in string.


local str = {}

function str.len( frame )
    local new_args = str._getParameters( frame.args, {'s'} );
    local s = new_args['s'] or '';
    
    return mw.ustring.len( s )
end

return str