Difference between revisions of "Module:String"

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

Latest revision as of 04:38, 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 s = frame.args[1]
    
    return mw.ustring.len( s )
end

return str