|
| 1 | +# pasteboard.paste() |
| 2 | + |
| 3 | +> --------------------- ------------------------------------------------------------------------------------------ |
| 4 | +> __Type__ [function][api.type.function] |
| 5 | +> __Revision__ [REVISION_LABEL](REVISION_URL) |
| 6 | +> __Keywords__ paste, pasteboard |
| 7 | +> __See also__ [Pasteboard][plugin.pasteboard] |
| 8 | +> [pasteboard.copy()][plugin.pasteboard.copy] |
| 9 | +> [pasteboard.clear()][plugin.pasteboard.clear] |
| 10 | +> --------------------- ------------------------------------------------------------------------------------------ |
| 11 | +
|
| 12 | + |
| 13 | +## Overview |
| 14 | + |
| 15 | +Pastes the top-most item on the pasteboard. |
| 16 | + |
| 17 | + |
| 18 | +## Gotchas |
| 19 | + |
| 20 | +Image copying/pasting is only supported on iOS. |
| 21 | + |
| 22 | + |
| 23 | +## Syntax |
| 24 | + |
| 25 | + pasteboard.paste( [listener] ) |
| 26 | + |
| 27 | +##### listener ~^(optional)^~ |
| 28 | +_[Function][api.type.Function]._ Listener function to be called when the paste is executed. This function is passed an `event` table which may contain the following properties, depending on the type of the data pasted: |
| 29 | + |
| 30 | +* `event.filename` ([string][api.type.String]) — Name of the image that was pasted. |
| 31 | +* `event.baseDir` ([constant][api.type.Constant]) — The base system directory of the pasted image. |
| 32 | +* `event.string` ([string][api.type.String]) — The pasted string. |
| 33 | +* `event.url` ([string][api.type.String]) — The pasted URL. |
| 34 | + |
| 35 | + |
| 36 | +## Example |
| 37 | + |
| 38 | +``````lua |
| 39 | +local pasteboard = require( "plugin.pasteboard" ) |
| 40 | + |
| 41 | +-- Callback function for the paste method |
| 42 | +local function onPaste( event ) |
| 43 | + |
| 44 | + -- Print the type of data on the pasteboard |
| 45 | + print( "Type of data:", pasteboard.getType() ) |
| 46 | + |
| 47 | + -- Paste an image |
| 48 | + if ( event.filename ) then |
| 49 | + print( "filename is:", event.filename ) |
| 50 | + print( "baseDir is:", event.baseDir ) |
| 51 | + end |
| 52 | + |
| 53 | + -- Paste a string |
| 54 | + if ( event.string ) then |
| 55 | + print( "string is:", event.string ) |
| 56 | + end |
| 57 | + |
| 58 | + -- Paste a URL |
| 59 | + if ( event.url ) then |
| 60 | + print( "URL is:", event.url ) |
| 61 | + end |
| 62 | +end |
| 63 | + |
| 64 | +pasteboard.paste( onPaste ) |
| 65 | +`````` |
0 commit comments