Skip to content

Commit

Permalink
String#*
Browse files Browse the repository at this point in the history
  • Loading branch information
Phrogz committed Jun 30, 2008
1 parent a849d5c commit a28f14a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions core/string.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@ String['+'] = createLuaFunc( 'stringToAppend', function( context ) -- String#+
return runtime.string[ runtime.luastring[context.self] .. toLuaString( context.stringToAppend ) ]
end )

String['*'] = createLuaFunc( 'reps', function( context ) -- String#*
local string = runtime.luastring[ context.self ]
local reps = runtime.luanumber[ context.reps ]
if not reps then
local theNextMessageOrLiteral = context.message.next
if theNextMessageOrLiteral == Lawn['nil'] then
error( "String#* is missing a repetition count" )
end
context.owningContext.nextMessage = theNextMessageOrLiteral.next
rvalue = runtime.luanumber[ sendMessage( context.owningContext, theNextMessageOrLiteral ) ]
end
return runtime.string[ string.rep( string, reps ) ]
end )

String.asCode = createLuaFunc( function( context ) -- String#asCode
return runtime.string[ string.format( "%q", runtime.luastring[context.self] ) ]
end )

0 comments on commit a28f14a

Please sign in to comment.