Difference between revisions of "D2Editor:setExpression"

From Inspired-Lua Wiki
Jump to navigation Jump to search
Line 11: Line 11:
 
== Example  ==
 
== Example  ==
  
<source lang="lua">
+
<source lang="lua" highlight=9>
 
function on.create()
 
function on.create()
 
editor = D2Editor.newRichText()
 
editor = D2Editor.newRichText()

Revision as of 11:50, 11 June 2011

D2Editor:setExpression is a function that is part of the D2Editor Library.


This function sets the contents of a D2Editor, and is a synonym of setText.

Syntax

D2Editor:setExpression(text, [cursor], [selection])
Sets the content to text, or appends it to a certain position if cursor is set. If selection is -1, no text is selected (?).

Example

function on.create()
	editor = D2Editor.newRichText()
	editor:move(0,0)
	editor:resize(200,100)
end

function on.charIn(char)
	currentText = editor:getText()
	editor:setExpression(currentText .. char) -- or setText(...)
	--Add char to the editor
end

function on.enterKey()
	on.charIn(string.char(10))
	--Add a new line
end

A very simple text editor (its actually more complicated that it be, but it shows the basics).

See also