Skip to content

Instantly share code, notes, and snippets.

Created September 10, 2015 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/d280e47c1a8346600b7e to your computer and use it in GitHub Desktop.
Save anonymous/d280e47c1a8346600b7e to your computer and use it in GitHub Desktop.
Smooth text scrolling for Codea
--# Main
-- TextScroll
function setup()
touching = false
yspeed = 0
ypos = HEIGHT/2
font("AmericanTypewriter")
textWrapWidth(WIDTH*0.9)
a = "1 – IntroductionLua is an extension programming language designed to support general procedural programming with data description facilities. Lua also offers good support for object-oriented programming, functional programming, and data-driven programming. Lua is intended to be used as a powerful, lightweight, embeddable scripting language for any program that needs one. Lua is implemented as a library, written in clean C, the common subset of Standard C and C++.As an extension language, Lua has no notion of a 'main' program: it only works embedded in a host client, called the embedding program or simply the host. The host program can invoke functions to execute a piece of Lua code, can write and read Lua variables, and can register C functions to be called by Lua code. Through the use of C functions, Lua can be augmented to cope with a wide range of different domains, thus creating customized programming languages sharing a syntactical framework. The Lua distribution includes a sample host program called lua, which uses the Lua library to offer a complete, standalone Lua interpreter, for interactive or batch use.Lua is free software, and is provided as usual with no guarantees, as stated in its license. The implementation described in this manual is available at Lua's official web site, www.lua.org.Like any other reference manual, this document is dry in places. For a discussion of the decisions behind the design of Lua, see the technical papers available at Lua's web site. For a detailed introduction to programming in Lua, see Roberto's book, Programming in Lua.2 – Basic ConceptsThis section describes the basic concepts of the language.2.1 – Values and TypesLua is a dynamically typed language. This means that variables do not have types; only values do. There are no type definitions in the language. All values carry their own type.All values in Lua are first-class values. This means that all values can be stored in variables, passed as arguments to other functions, and returned as results.There are eight basic types in Lua: nil, boolean, number, string, function, userdata, thread, and table. The type nil has one single value, nil, whose main property is to be different from any other value; it usually represents the absence of a useful value. The type boolean has two values, false and true. Both nil and false make a condition false; any other value makes it true. The type number represents both integer numbers and real (floating-point) numbers. The type string represents immutable sequences of bytes. "
parameter.number("slide", 1, 100, 15)
end
function draw()
background(40, 40, 50)
if not touching then
yspeed = yspeed-yspeed/slide
end
ypos = ypos + yspeed
translate(WIDTH/2, ypos)
text(a.."Lua is also encoding-agnostic; it makes no assumptions about the contents of a string.The type number uses two internal representations, or two subtypes, one called integer and the other called float. Lua has explicit rules about when each representation is used, but it also converts between them automatically as needed (see §3.4.3). Therefore, the programmer may choose to mostly ignore the difference between integers and floats or to assume complete control over the representation of each number. Standard Lua uses 64-bit integers and double-precision (64-bit) floats, but you can also compile Lua so that it uses 32-bit integers and/or single-precision (32-bit) floats. The option with 32 bits for both integers and floats is particularly attractive for small machines and embedded systems. (See macro LUA_32BITS in file luaconf.h.)Lua can call (and manipulate) functions written in Lua and functions written in C (see §3.4.10). Both are represented by the type function.The type userdata is provided to allow arbitrary C data to be stored in Lua variables. A userdata value represents a block of raw memory. There are two kinds of userdata: full userdata, which is an object with a block of memory managed by Lua, and light userdata, which is simply a C pointer value. Userdata has no predefined operations in Lua, except assignment and identity test. By using metatables, the programmer can define operations for full userdata values (see §2.4). Userdata values cannot be created or modified in Lua, only through the C API. This guarantees the integrity of data owned by the host program.")
end
function touched(touch)
if touch.state == BEGAN then
touching = true
elseif touch.state == ENDED then
touching = false
else
yspeed = touch.deltaY
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment