0% found this document useful (0 votes)
3 views

Lua Programming Beginners Learn Lua Programming Step By Step Very Easy Rizk instant download

The document provides a comprehensive guide for beginners to learn Lua programming step by step, including essential concepts such as variables, functions, and control structures. It also lists various recommended Lua programming books and resources for further learning. Additionally, it outlines the structure of the Lua language and offers examples to illustrate programming techniques.

Uploaded by

janorisavio33
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Lua Programming Beginners Learn Lua Programming Step By Step Very Easy Rizk instant download

The document provides a comprehensive guide for beginners to learn Lua programming step by step, including essential concepts such as variables, functions, and control structures. It also lists various recommended Lua programming books and resources for further learning. Additionally, it outlines the structure of the Lua language and offers examples to illustrate programming techniques.

Uploaded by

janorisavio33
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 76

Lua Programming Beginners Learn Lua Programming

Step By Step Very Easy Rizk download

https://ebookbell.com/product/lua-programming-beginners-learn-
lua-programming-step-by-step-very-easy-rizk-37070252

Explore and download more ebooks at ebookbell.com


Here are some recommended products that we believe you will be
interested in. You can click the link to download.

Lua Programming Beginners Learn Lua Programming Step By Step Very Easy
Rizk

https://ebookbell.com/product/lua-programming-beginners-learn-lua-
programming-step-by-step-very-easy-rizk-232145960

Lua Programming Gems Illustrated Luiz Henrique De Figueiredo

https://ebookbell.com/product/lua-programming-gems-illustrated-luiz-
henrique-de-figueiredo-54831260

Beginning Lua Programming 1st Edition Jung Kurt

https://ebookbell.com/product/beginning-lua-programming-1st-edition-
jung-kurt-55199762

Beginning Lua Programming 1st Edition Kurt Jung Aaron Brown

https://ebookbell.com/product/beginning-lua-programming-1st-edition-
kurt-jung-aaron-brown-5468708
Beginning Lua Programming Kurt Jung Aaron Brown

https://ebookbell.com/product/beginning-lua-programming-kurt-jung-
aaron-brown-59266488

Lve For Lua Game Programming 1st Edition Akinlaja Darmie

https://ebookbell.com/product/lve-for-lua-game-programming-1st-
edition-akinlaja-darmie-43150088

Programming In Lua 4th Edition Roberto Ierusalimschy

https://ebookbell.com/product/programming-in-lua-4th-edition-roberto-
ierusalimschy-49119332

Programming In Lua 2nd Edition Roberto Ierusalimschy

https://ebookbell.com/product/programming-in-lua-2nd-edition-roberto-
ierusalimschy-23299570

Programming In Lua 3rd Edition Roberto Ierusalimschy

https://ebookbell.com/product/programming-in-lua-3rd-edition-roberto-
ierusalimschy-4415838
By Claudia Alves
& Alexander Aronowitz

TABLE OF
CONTENTS
Introduction The audience
About the third edition Other
resources Certain
Typographical Conventions
Running examples
Acknowledgments PART I
Language Chapter 1. Getting
Started 1.1. Blocks 1.2. Some
lexical conventions 1.3. Global
variables 1.4. Separate
interpreter
Chapter 2. Types and values
2.1. Nil 2.2. Boolean 2.3.
Numbers 2.4. Strings
Literals
Long lines
Type conversions

2.5. Tables 2.6. Functions 2.7.


userdata and threads
Exercises Chapter 3.
Expressions 3.1. Arithmetic
Operators 3.2. Comparison
operators 3.3. Logical
operators 3.4. Concatenation
3.5. Length operator 3.6.
Operator Priorities 3.7. Table
constructors Exercises
Chapter 4. Operators 4.1.
Assignment operators 4.2.
Local variables and blocks 4.3.
Control structures
if then else
while
repeat
Numeric for statement
General for statement

4.4. break, return and goto


Exercises Chapter 5.
Functions 5.1. Multiple
Results 5.2. Functions with a
variable number of arguments
5.3. Named arguments
Exercises Chapter 6. More
about functions 6.1. Closures
6.2. Non-global functions 6.3.
Optimization of tail calls
Exercises Chapter 7. Iterators
and the generic for 7.1.
Iterators and Closures 7.2.
Generic for semantics 7.3.
Stateless iterators 7.4.
Complex State Iterators 7.5.
True iterators Exercises
Chapter 8. Compilation,
Execution, and Errors 8.1.
Compilation 8.2. Precompiled
Code 8.3. C code 8.4. Errors
8.5. Error and Exception
Handling 8.6. Error messages
and call stack
Chapter 9. Coroutines 9.1.
Basics of coroutines 9.2.
Channels and Filters 9.3.
Coroutines as iterators 9.4.
Non-displacing multi-
threading Exercises Chapter
10. Completed Examples 10.1.
The problem of eight queens
10.2. The most common words
10.3. Markov chain Exercises
PART II Tables and Objects
Chapter 11. Data Structures
11.1. Arrays 11.2. Matrices
and multidimensional arrays
11.3. Linked Lists 11.4.
Queues and double queues
11.5. Sets and Sets 11.6. Line
buffers 11.7. Counts Exercises
Chapter 12. Data Files and
Persistence 12.1. Data files
12.2. Serialization
Saving tables without loops
Saving tables with loops

Chapter 13. Metatables and


Metamethods 13.1. Arithmetic
metamethods 13.2.
Comparison Methods 13.3.
Library Metamethods 13.4.
Methods for accessing the
table
__Index metamethod
__Newindex metamethod
Default tables
Tracking access to a table
Read-only tables

Exercises Chapter 14.


Environment 14.1. Global
variables with dynamic names
14.2. Descriptions of global
variables 14.3. Non-global
environments 14.4. Using
_ENV 14.5. _ENV and load
Exercises Chapter 15.
Modules and Packages 15.1.
Require function
Renaming a module
Search along the path
File crawlers

15.2. The Standard Approach


for Writing Lua Modules 15.3.
Using environments 15.4.
Submodules and Packages
Exercises Chapter 16. Object
Oriented programming 16.1.
Classes 16.2. Inheritance 16.3.
Multiple inheritance 16.4.
Hiding 16.5. Single Method
Approach Exercises Chapter
17. Weak Tables and
Finalizers 17.1. Weak tables
17.2. Functions with caching
17.3. Object Attributes 17.4.
Again tables with default
values 17.5. Ephemeral tables
17.6. Finalizers
Exercises

PART III Standard Libraries


Chapter 18. Math Library
Exercises Chapter 19. Library
for Bitwise Operations
Exercises Chapter 20. Library
for Working with Tables 20.1.
Insert and remove functions
20.2. Sorting 20.3.
Concatenation Exercises
Chapter 21. Library for
working with strings 21.1.
Basic functions for working
with strings 21.2. Functions
for working with templates
String.find function
String.match function
String.gsub function
String.gmatch function

21.3. Templates 21.4. Grips


21.5. Substitutions
URL encoding
Replacing tabs

21.6. Tricky tricks 21.7.


Unicode Exercises Chapter 22.
Library I / O 22.1. Simple I /
O Model 22.2. Full I / O model
A small trick to increase performance
Binaries
22.3. Other operations with
files Exercises Chapter 23.
Library of operating room
functions systems 23.1. Date
and time 23.2. Other system
calls Exercises Chapter 24.
Debug Library 24.1.
Accessibility (introspection)
Accessing Local Variables
Access to non-local variables
Access to other coroutines

24.2. Hooks 24.3. Profiling


Exercises
PART IV WITH API Chapter
25. Overview of the C API
25.1. First example 25.2. Stack
Putting items on the stack
Referring to items
Other stack operations
25.3. Error handling in the C
API
Handling errors in the application code
Error handling in the library code

Exercises Chapter 26.


Extending Your Application
26.1. Basics 26.2. Working
with tables 26.3. Lua function
calls 26.4. Generalized
function call Exercises
Chapter 27. Calling C from
Lua 27.1. Functions on C 27.2.
Continuations 27.3. C modules
Exercises Chapter 28.
Techniques for writing
functions in C 28.1. Working
with arrays 28.2. Working
with strings 28.3. Saving state
in functions on C
Register
Function related values
Function related values used
several functions

Exercises Chapter 29. User-


Defined Types in C 29.1. User
data (userdata) 29.2.
Metatables 29.3. Object
Oriented Access 29.4. Access
as an ordinary array 29.5.
Light objects of type userdata
(light userdata) Exercises
Chapter 30. Resource
Management 30.1. Directory
iterator 30.2. XML Parser
Exercises Chapter 31. Threads
and States 31.1. Numerous
threads 31.2. Lua States
Exercises Chapter 32.
Memory Management 32.1.
Memory allocation function
32.2. Garbage collector
Garbage collector API

Exercises

Begin Chapter 1

Continuing the tradition, our first Lua


program simply printed em “Hello World” : print
(“Hello World”) If you are using a separate Lua
interpreter, then all you need is you need to
run your first program - this is to run the
interpreter tator - usually called lua or lua5.2 -
with the name of the text file containing your
program. If you saved the above the above
program in hello.lua file , then you should run
following command:

% lua hello.lua

As a more complex example, our next


program defines There is a function for
calculating the factorial of a given number,
asking gives the user a number and prints its
factorial:

- defines a factorial function

function fact (n)


if n == 0 then
return 1
else
return n * fact (n-1)
end
end
print (“enter a number:”)
a = io.read (“* n”) - reads a number
print (fact (a))

1.1. Blocks
Every piece of code that Lua executes, such
as a file or from- a smart string in interactive
mode is called a chunk. A block is simply a
sequence of commands (or statements). Lua
does not need a separator between
consecutive operators, but you can use
semicolon if you like. I personally use I use a
semicolon only to separate statements written
in one line. Line splitting does not play any
role in the syntax system Lua; so, the
following four blocks are valid and
equivalent:

a=1
b=a*2
a = 1;
b = a * 2;
a = 1; b = a * 2
a = 1 b = a * 2 - ugly, but valid

A block can consist of just one statement, as


in the example "Hello World", or consist of a
set of operators and definitions functions
(which are actually just assignments, as we
will see later), as in the factorial example.
Block can be as great as you want. Since Lua
is also used as language for describing data,
blocks of several megabytes are not a rarity.
The Lua interpreter does not have any
problems with bot with large blocks.
Instead of writing your programs to a file,
you can run the interpreter interactively. If
you run- those lua without arguments, then
you will see its prompt for input:
% lua
Lua 5.2 Copyright (C) 1994-2012 Lua.org, PUC-Rio
>

Accordingly, each command that you enter


(like, for example measure, print “Hello World” )
is executed immediately after how you enter
it. To exit the interpreter, just type end-of-file
character ( ctrl-D in UNI, ctrl-Z in Windows) or
call the exit function from the operating
system library - you need type os.exit () . In
interactive mode, Lua usually interprets each
the line you enter as a separate block.
However, if he is detects that the line is not a
complete block, then it waits continue typing
until a complete block is obtained. This way
you can enter multi-line definitions, so as a
factiorial function , directly interactively. One-
but it is usually more convenient to place
such definitions to a file and then call Lua to
execute that file. You can use the –i option to
force Lua switch to interactive mode after
executing the given block ka:

% lua -i prog

A command like this will execute the block in


the prog file and then go into interactive mode.
This is especially useful for debugging and
manual th testing. At the end of this chapter,
we will look at other options. command line
for the Lua interpreter. Another way to
trigger blocks is the dofile function , which
paradise executes the file immediately. For
example, let's say you have lib1.lua file with
the following code:
function norm (x, y)
return (x ^ 2 + y ^ 2) ^ 0.5
end
function twice (x)
return 2 * x
end
Then interactively you can type

> dofile (“lib1.lua”) - load your library


> n = norm (3.4, 1.0)
> print (twice (n)) -> 7.0880180586677

The dofile function is also useful when you are


testing a piece of code. You can work with
two windows: one contains the text editor
with your program (for example, in the prog.lua
file ), and in other gom is a console running
the Lua interpreter in the inter- active mode.
After you have saved the changes to your
program, you do dofile (“prog.lua”) in the console
to load ki new code; then you can start using
the new code, calling functions and printing
the results.

1.2. Some lexical


agreements
Identifiers (or names) in Lua are strings from
Latin their letters, numbers and underscores
that do not start with a number;
eg:

ij i10 _ij
aSomewhatLongName _INPUT

You are better off avoiding identifiers


consisting of underscores vana followed by
capital Latin letters (for example, _VERSION );
they are reserved for special purposes in Lua.
I usually use id _ (single underscore)
for dummy variables. In older versions of
Lua, the concept of what a letter is depended
on from the locale. However, these letters
make your program unsuitable to run on
systems that do not support this locale.
Therefore, Lua 5.2 considers only letters as
letters. from the following ranges: AZ and az .
The following words are reserved, you cannot
use them as identifiers:

and break do
else elseif
end false goto for function
if in
local nil not
or repeat return then true
until while

Lua is case sensitive: and is a reserved word,


however, And and AND are two different
identifiers. The comment starts with two
minus signs ( - ) and continues with- until the
end of the line. Lua also supports block
comments, which starts with - [[ and goes to
the next ]] 1 . Standard the way to comment
out a piece of code is to put it between
- [[ and -]] as shown below:

- [[
print (10) - no action (commented out)
-]]

To make this code active again, just add one


minus to the first line:

--- [[
print (10) -> 10
-]]

In the first example - [[ in the first line starts a


block com- mentary, and the double minus in
the last line is also in this comment. In the
second example --- [ starts the usual single line
comment, so the first and last lines
become regular independent comments. In
this case print is outside of comments.

1.3. Global Variables


Global variables do not need descriptions;
you just use them you whine. It is not an error
to refer to uninitialized variable; you just get
nil as a result- that:

print (b) -> nil


b = 10
print (b) -> 10

If you assign nil to a global variable, Lua will


itself as if this variable has never been used:

b = nil
print (b) -> nil

After this assignment, Lua may eventually


regain its password. the space occupied by
this variable.

1.4. Separate
interpreter
Stand-alone interpreter (also called lua.c in
relation to the name of its source file or just
lua by name executable file) is a small
program that allows direct use of Lua. This
section presents her basic options.
When the interpreter loads a file, it skips the
first string if it starts with '#' character . This
allows you to use make Lua a scripting
interpreter on UNIX systems. If you start
your script with something like
#! / usr / local / bin / lua

(assuming the interpreter is in / usr / local / bin )


or
#! / usr / bin / env lua ,

then you can directly run your script without


explicitly start the Lua interpreter. The
interpreter is called like this:
lua [options] [script [args]]

All parameters are optional. As we have seen,


when we start If lua has no arguments, it goes
into interactive mode.
The -e option allows you to directly specify
the code directly in the commandline like
below:

% lua -e “print (math.sin (12))” -> -0.53657291800043

(UNIX requires double quotes so that the


command interpreter the torus (shell) did not
parse parentheses).
The –l option loads the library. As we have
seen previously, -i pe- puts the interpreter into
interactive mode after processing the OS
arguments. So the next call will load the
library lioteku lib , then execute the
assignment x = 10 and finally pass into
interactive mode.
% lua -i -llib -e “x = 10”

Interactively, you can print the value of the


expression by simply typing a line that starts
with an equal sign for
followed by the expression:
> = math.sin (3) -> 0.14112000805987
> a = 30
> = a -> 30

This feature allows Lua to be used as a


calculator. Before executing its arguments,
the interpreter looks for re- environment
variable named LUA_INIT_5_2 or, if such a
change no, no, LUA_INIT . If one of these
variables is present and its has the form
@filename , the interpreter launches this file.
If LUA_INIT_5_2 (or LUA_INIT ) is defined but
not start- is started with the '@' character ,
then the interpreter assumes that it contains
executable Lua code and executes it. LUA_INIT
gives huge the ability to configure the
interpreter, since when configuration, all the
power of Lua is available to us. We can
download packages, change the current path,
define your own functions change, rename or
delete functions, etc. The script can get its
arguments in a global variable
arg . If we have a call like % lua script abc , then
the interpreter creates arg table with all
command line arguments before by executing
the script. The script name is located at index
0, per the first argument (in the example it is
“a” ) is located at index 1, and so on. The
preceding options are arranged in negative
indices, as they appear before the script
name. For example, ra- look at the following
call:

% lua -e “sin = math.sin” script ab

The interpreter collects arguments as follows:

arg [-3] = "lua"


arg [-2] = “-e”
arg [-1] = “sin = math.sin”
arg [0] = "script"
arg [1] = “a”
arg [2] = “b”
Most often the script uses only positive
indices (in the example, these are arg [1] and
arg [2] ).
Since Lua 5.1 the script can also receive its
arguments using the expression ... (three
dots). In the main part of the script, this is
expression gives all the arguments of the
script (we will discuss similar expressions
(see section 5.2).

Exercises
Exercise 1.1 . Run the factorial example.
What will happen
with your program if you enter a negative
number?
Modify the example to avoid this problem.
Exercise 1.2 . Run the twice example by
loading once
file using the –l option , and another time
using dofile . what
faster?
Exercise 1.3 . Can you name another
language using
(-) for comments?
Exercise 1.4 . Which of the following lines
are valid
by our identifiers?
___ _end End end until? nil NULL

Exercise 1.5 . Write a simple script that


prints
your name without knowing it in advance.

CHAPTER 2 Types
and values
Lua is a dynamically typed language. The
language has no definitions of ty-pov, each
value carries its own type.
There are eight basic types in Lua: nil ,
boolean , number , string , userdata , function
, thread and table . The type function returns
the type for any passed value:

print (type (“Hello world”))


-> string
print (type (10.4 * 3))
-> number
print (type (print))
-> function
print (type (type))
-> function
print (type (true))
-> boolean
print (type (nil))
-> nil
print (type (type (X)))
-> string

The last line will always return string


regardless of the value Niya the X , as the
result of a function type is always a string.
Variables have no predefined types; any
variable can contain values of any type:

print (type (a)) -> nil ('a' not yet defined)


a = 10
print (type (a)) -> number
a = “a string !!”
print (type (a)) -> string
a = print
-- Yes it is possible!
a (type (a))
-> function

Notice the last two lines: functions are first


class values in Lua; they can be manipulated
like any other values. (More on this in
Chapter 6.) Usually when you use the same
variable for value different types, you get
disgusting code. However, sometimes
judicious use of this opportunity is beneficial,
for example using nil to distinguish normal
return value from any error.

2.1. Nil
Nil is a type with only one value, nil , the
main which is different from all other values.
Lua
uses nil to indicate a missing value. Like us
already seen, globals default to nil before its
first assignment, you can also assign nil a
global variable to delete it.
2.2. Boolean (boolean
values)
The boolean type has two values, true and
false , which serve to pre- setting traditional
logical values. However, these values do not
monopolize all conditional values: in Lua,
any value can represent a condition. Relevant
checks (checking conditions in various
control structures) interpret both nil and false
as false and all other values as valid muddy.
In particular, Lua treats zero and an empty
string as true. in logical conditions.
Throughout the book, false will mean nil. and
false . In the case when it is about boolean
values, there will be explicitly set to false .

2.3. Numbers
The number type represents floating point
values specified with double precision. Lua
does not have a built-in integer type.
Some fear that even simple operations such
as increase by one (increment) and
comparison, may be incorrect work with
floating point numbers. However, in fact it
isnot this way. Almost all platforms now
support the standard IEEE 754 for floating
point representation. According to this
standard, the only possible source of errors is
There is a case where the number cannot be
accurately represented. Opera- walkie-talkie
rounds its result only if the result cannot be
accurately represented as the corresponding
float value point. Any operation whose result
can be accurately predicted put, will have the
exact meaning. In fact, any integer up to 2 53
(approximately 10 16 ) has an exact floating
point representation with double precision.
When you use a float value doubleprecision
dot to represent integers, no rounding errors
unless the value is greater than 2 5353 bit
integer values without rounding problems. Of
course, fractional numbers will have rounding
problems. This the situation is no different
than when you have paper and a pen. If we
want to write 1/7 in decimal form, then we
must somewhere us stop. If we use ten digits
to represent number, then 1/7 becomes
0.142857142 . If we calculate 1/7 * 7 s ten digits,
we get 0.999999994 , which is different from 1.
Moreover, numbers that have a finite
representation in the form decimal fractions
can have an infinite representation in the
form binary fractions. So, 12.7-20 + 7.3 is not
zero, since both numbers 12.7 and 7.3 do not
have an exact binary representation (see
Figure 2.3). Before we continue, remember
that integers have an exact representation and
therefore have no rounding errors. Most
modern CPUs perform floating operations.
dot as fast (or even faster) than with integers.
However, it is easy to compile Lua so that for
numeric values a different type was used, for
example long integers single-precision
floating-point values or numbers. It especially
useful for platforms without hardware
support for numbers with floating point such
as embedded systems. For de- For this, refer
to the luaconf.h file in the Lua source files. We
can write numbers, if necessary, specifying a
fraction part and decimal degree. Examples
of valid numeric constants are:
4 0.4 4.57e-3 0.3e12 5E + 20

Moreover, we can also use hexadecimal


constants starting at 0x . Since Lua 5.2
hexadecimal constants can also have a
fractional part and a binary power (ne- 'p' or 'P'
is used before the degree ), as in the
following examples:

0xff (255) 0x1A3 (419) 0x0.2 (0.125) 0x1p-1 (0.5)


0xa.bp2 (42.75)

(We've added a decimal representation for


each constant.)

2.4. Strings
Lua strings have the usual meaning: a
sequence of characters fishing. Lua supports
all 8-bit characters, and strings can be keep
characters with any codes, including zeros. It
means that you can store any binary data as
strings. you also you can store unicode strings
in any representation (UTF-8, UTF-16, etc.).
The standard library that comes with Lua is
does not contain built-in support for these
views. However less, you may well be
working with UTF-8 strings, which we will
consider Rome in section 21.7. Lua strings
are immutable values. You can not change
the character inside the string, as you can in
C; instead of this you create a new line with
the desired changes as shown in following
example:

a = “one string”
b = string.gsub (a, “one”, “another”) - change part of the
string
print (a) -> one string
print (b) -> another string

Lua strings are subject to automatic memory


management, just like other Lua objects
(tables, functions, etc.). This is a sign cheat
that you don't have to worry about allocating
and freeing lines; Lua will do it for you. The
string can be one character or a whole book.
Programs that work with lines of 100K or
10M characters are not uncommon in Lua.
You can get the length of a string using as a
prefix operator '#' (called length operator):

a = “hello”
print (#a) -> 5
print (# "good \ 0bye") -> 8

Literals

We can put strings inside single or double


quotes- check:
a = “a line”
b = 'another line'

These types of records are equivalent; the


only difference is what is inside a string,
limited to one type of quotation marks, you
can directly insert quotation marks of a
different type. Usually most programmers use
quotation marks of one type for the same
string type. For example, a library that works
with XML, can use single quotes for strings,
containing XML fragments, since these
fragments often contain
double quotes. Lua strings can contain the
following escape sequence nos:
\a
bell
\b
Back space
\f
page translation (form feed)
\n
newline
\r
carriage return
\t
tab (horizontal tab)
\v
vertical tab
\\
backslash
\"
double quote
\'
single quote

The following example illustrates their use:

> print (“one line \ nnext line \ n \” in quotes \ ”, 'in


quotes'”)
one line
next line
“In quotes”, 'in quotes'
> print ('a backslash inside quotes: \' \\\ '')
a backslash inside quotes: '\'
> print (“a simpler way: '\\'”)
a simpler way: '\'
We can specify a character in a string using
its numeric value using constructions like \
ddd and \ x \ hh , where ddd is a sequence of
no more than three decimal digits, and hh is a
sequence of exactly two hexadecimal digits.
As complex example two lines “alo \ n123 \” ”
and '\ 97lo \ 10 \ 04923”' have the same meaning
on a system using ASCII: 97 is the ASCII
code for 'a' , 10 is the code for the line feed
character, and 49 is the code for the digit '1'
(in this example we should write the value 49
using three decimal digits \ 049 , because it is
followed by another number; otherwise Lua
interpreted it as code 492). We we can also
write the same string as ' \ x61 \ x6c \ x6f \ x0a \
x31 \ x32 \ x33 \ x22 ' , representing each character
in its sixteen
normal value.

Long lines
We can delimit character strings with double
square brackets, as we did with the
comments. Line in this form can span many
lines, and control sequences the numbers on
these lines will not be interpreted. Moreover,
this the form ignores the first character of the
line if it is a jump character next line. This
form is especially useful for writing lines,
containing large snippets of code as shown
below:

page = [[
<html>
<head>
<title> An HTML Page </title>
</head>
<body>
<a href=32http://www.lua.org> Lua </a>
</body>
</html>
]]
write (page)

Sometimes you may want to put something


like
a = b [c [i]] (note the ]] in this code) or you can
want to put in a line a piece of code where
some piece is already commented out. To
deal with such cases, you can use place any
number of equal signs between two opening
in square brackets, for example [=== [ . After
that the line will terminate only on a pair of
closing square brackets with the same the
most equal signs ( ] ===] for our example). The
scanner will ignore pairs of brackets with a
different number of values. kov equality. By
choosing a suitable number of equal signs
You can wrap any fragment in a string. The
same is true for comments. For example, if
you startthose long comment with - [= [ , then
it will continue all the way before ] =] . This
feature allows you to comment out any
fragment a code snippet containing already
commented out fragments.
Long lines are very handy for including text
in your code, but you shouldn't use them for
non-text strings. Although the lines in Lua
can contain any characters, this is not a good
idea - use these symbols in your code: you
may run into problems with your text editor;
moreover, lines of the form “\ R \ n” can
become “\ n” . Therefore, to represent the
arbitrary binary data, it is better to use control
software sequences starting with a \ , such as \
x13 \ x01 \ xA1 \ xBB ". However, this presents a
problem for long lines because of the
resulting length. For situations like this, Lua
5.2 offers a control after- the \ z sequence : it
skips all characters in the string up to the first
non-whitespace character. The following
example illustrates its use use:
data = “\ x00 \ x01 \ x02 \ x03 \ x04 \ x05 \ x06 \ x07 \ z
\ x08 \ x09 \ x0A \ x0B \ x0C \ x0D \ x0E \ x0F "

\Z at the end of the first line skips the


following
end of line and indentation of next line so that
byte
\ x07 immediately followed by a byte \ x08 in
the resulting row.

Type casts
Lua provides automatic conversion of values
between
strings and numbers at run time. Any numeric
operation
applied to a string, tries to convert the string
to a number:

print (“10” + 1) -> 11


print (“10 + 1”) -> 10 + 1
print (“- 5.3e-10” * ”2”) -> -1.06e-09
print (“hello” + 1) - ERROR (cannot convert “hello”)
Lua applies similar conversions not only in
arithmetic operators, but also in other places
where the expected number, for example for
the math.sin argument . Similarly, when Lua
expects to receive a string, but receives a
number, it converts the number to string:

print (10 .. 20) -> 1020

(The .. operator is used in Lua to concatenate


strings. When you use it write immediately
after the number, then you must separate
them from each a friend with a space;
otherwise Lua will assume that the first point
is decimal point of the number.) Today we
are not sure if these automatic conversions
types were a good idea in Lua design. It is
generally best on do not count them. They are
handy in some places; but adding- There are
complexities in both the language and the
programs that use them. After all, strings and
numbers are different types despite
everything these transformations. A
comparison like 10 = "10" gives a false value,
because 10 is a number and “10” is a string. If
you need to explicitly convert a string to a
number, then you can use the tonumber function
, which returns nil if string ka does not
contain a number:

line = io.read ()
- read the line
n = tonumber (line)
- try to translate it into a number
if n == nil then
error (line .. “is not a valid number”)
else
print (n * 2)
end

To convert a number to a string, you can use


the function tion tostring or concatenate the
number with an empty string:

print (tostring (10) == “10”)


-> true
print (10 .. “” == “10”)
-> true

These transformations always work.

2.5. Tables
The table type corresponds to an associative
array. Associative a ny array is an array that
can be indexed not only numbers, but also
strings or any other value from the language,
except for nil .
Tables are the main (actually the only) place
a hanism for structuring data in Lua, and very
powerful. We use tables to represent regular
arrays, sets, records and other data structures
simple, homogeneous and in an efficient way.
Lua also uses tables to pre- placing packages
and objects. When we write io.read , we think-
This is about the “ read function from the io
module ”. For Lua, this expression means
"Take the value from the io table by the read
key . " Lua tables are neither values nor
variables; they objects . If you are familiar
with arrays in Java or Scheme, then you
should you know what I mean. You can think
of a table as dynamically allocated object;
your program only works with a link
(pointer) to it. Lua never uses covert copying
or creating new tables. Moreover, you even
no need to declare a table in Lua; in fact there
is not even a way declare a table. You create
tables using a special expression, which in the
simplest case looks like {} ;

a = {}
- create a table and remember the link to it in 'a'
k = “x”
a [k] = 10
- new record with key "x" and value 10
a [20] = “great” –- new record with key 20 and value
“great”
print (a [“x”]) -> 10
k = 20
print (a [k]) -> “great”
a [“x”] = a [“x”] + 1 –- increase the record “x”
print (a [“x”]) -> 11

The table is always anonymous. There is no


permanent connection between the variable
that contains the table and the table itself:

a [“x”] = 10
b=a
- 'b' refers to the same table as 'a'
print (b [“x”]) -> 10
b [“x”] = 20
print (a [“x”]) -> 20
a = nil - only 'b' still refers to the table
b = nil - there are no references to the table

When there are no more references to the


table left in the program, the collector
garbage in Lua will eventually destroy the
table and reuse it memory. Each table can
contain values with different types of dex,
and the table grows as new records are added:

a = {}
- empty table
- create 1000 new entries
for i = 1, 1000 do a [i] = i * 2 end
print (a [9]) -> 18
a [“x”] = 10
print (a [“x”]) -> 10
print (a [“y”]) -> nil

Pay attention to the last line: as with the


global variables, uninitialized table fields
return nil . As with global variables, you can
assign the table field is nil to destroy it. This
is not a coincidence: Lua stores global
variables in regular tables. We we'll take a
closer look at this in Chapter 14. To represent
records, you use the field name as an index.
Lua supports this view by offering the
following syntax sic sugar ": instead of a ["
name "] you can write a.name . So Thus, we can
rewrite the last few lines of the previous the
following example in a cleaner way:

ax = 10 - same as a [“x”] = 10
print (ax) - same as print (a [“x”])
print (ay) - same as print (a [“y”])

For Lua, these two forms are completely


equivalent and can be
freely used. For the reader, however, each
form can
communicate a specific intent. Dot notation
clearly
shows that we are using the table as a record
(structure), where y
we have a certain set of given, predefined
keys.
Another entry suggests that the table can be
used
use any string as a key and for some reason in
this place we work with a specific key.
A common newbie mistake is that
they confuse ax and a [x] . The first form
actually matches
a [“x”] , that is, referring to the table with the
key “x” . In the second case the key is the
value of the variable x . Shown below
difference:
a = {}
x = “y”
a [x] = 10 - write 10 in the “y” field
print (a [x]) -> 10 - value of the "y" field
print (ax) -> nil - value of field “x” (undefined)
print (ay) -> 10 - value of the field "y"

To represent a traditional array or list, simply


use
use a table with integer keys. There is no
way, no
the need to declare size; you just initialize
those elements
the cops you need:
- read 10 lines, memorizing them in the table
a = {}
for i = 1, 10 do

a [i] = io.read ()
end

Since you can index the table by any value


you can start indices in an array with any
number that
you like. However, it is customary in Lua to
start arrays with one. (not from scratch as in
C) and some Lua tools stick to this
th agreement.
Usually, when you are working with a list,
you need to know its length. It can be
constant or it can be written somewhere.
Usually
we write the length of the list in a field with a
non-numeric key; by history For logical
reasons, some programs use for these
purposes
Leave the field “n” .
Often, however, the length is not explicitly
specified. Since anyone who does not the
value of nil corresponds to the initialized
field , then we can use use this value to
determine the end of the list. For instance,
if you've read ten lines into a list, it's easy to
remember that its
the length is 10, since its keys are the
numbers 1, 2,…, 10.
This approach only works with lists that have
no holes , which
they contain the value nil . We call such lists
of sequences
sequences .
For sequences, Lua offers the '#' length
operator. is he
returns the last index or length of a sequence.
On
example, you can print the lines read in the
previous
example using the following code:
- print the lines
for i = 1, #a do
print (a [i])

end

Since we can index the table with values of


any
type, then when indexing a table, the same
subtleties arise as
and when checking for equality. Although we
can index the table and using the integer 0 ,
and using the string “0” , these two mean The
values are different and correspond to
different elements of the table. Analogically,
the lines “+1” , “01” and “1” also correspond to
different elements table cops. When you are
unsure about the type of your indexes, use
explicit casting:
i = 10; j = “10”; k = "+10"
a = {}
Another Random Scribd Document
with Unrelated Content
however their opinions might differ from those of the Indians.” This
severe rebuke from the chief instantly silenced Jim, who quietly and
respectfully joined the rest of the party, at White-cloud’s request, who
seated themselves in the room where the talk was to be held. The
pipe was lit and passing around, while one of the reverend gentlemen
stated the views with which they had come to visit them, and asked
the Indians if it was perfectly convenient and agreeable for them to
hear what they had to say, to which the chief replied in the
affirmative. The reverend gentleman then proceeded with his
remarks upon the importance of education and religion, the nature of
which the reader can easily imagine, and save the time it would
require to record them here. To these the chiefs and all the party
(excepting Jim and the Doctor, who had fallen asleep) listened with
patience and profound silence, as the pipe was passing around. The
reverend gentleman having finished, the War-chief took a few deep-
drawn breaths through the pipe, and passing it along, said—
“My Friends,—I speak for the chief who is here, and not very well.
My words are his words, and the words of all our party. We have
heard what you had to say, because we had promised to do so.
“My Friends,—We have talked many times on this subject, and
some of our talks have been long; but at this time our words will
be few, for we are weary, and as we have before said, we are poor,
and our wives and children are hungry, and we have come over
here to try to make some money to get them warm clothes and
food to eat. (How, how, how!)
“My Friends,—Many of our children are now in schools in our
country, and the ‘good book’ which is in your hands is in their
hands at this time. We believe that the Great Spirit has made our
religion good and sufficient for us if we do not in any way offend
him. We see the religion of the white people dividing into many
paths, and we cannot believe that it is pleasing to the Great Spirit.
The Indians have but one road in their religion, and they all travel
in that, and the Great Spirit has never told them that it was not
right.
“My Friends,—Our ears have been open since we came here, and
the words we have heard are friendly and good; but we see so
many kinds of religion, and so many people drunk and begging
when we ride in the streets, that we are a little more afraid of
white man’s religion than we were before we came here.
“My Friends,—The Indians occupied all the fine hunting grounds
long before the white men came to them, but the white men own
them nearly all now, and the Indians’ hunting grounds are mostly
all gone. The Indians never urge white men to take up their
religion, they are satisfied to have them take a different road, for
the Indians wish to enjoy their hunting grounds to themselves in
the world to come. (How, how, how!)
“My Friends,—We thank you, and shall wish the Great Spirit may be
kind to you. I have no more to say.”
Thus ended the conversation this time, and the Indians all rising
(except the Doctor, who was still asleep) shook hands with the
clergymen and retired to their own room.
These excellent gentlemen then expressed to Mr. Melody and myself
their high admiration and respect for them as men, and said that
they could make every allowance for them, travelling here only for
the laudable objects which they had so clearly explained, and their
patience taxed in so many instances as I had mentioned, of a similar
nature. They agreed that it would be cruel to urge them to listen any
further under their present circumstances, and that they had already
exercised far greater patience than white men would in a similar
condition. They said they should feel bound to call on another day
(and did so), not to talk with them about religion, but to bring them
some presents that would be serviceable to their wives and little
children, and took leave.
CHAPTER XX.
The Doctor and Jim visit several churches—The Indians in St. Paul’s—In
Westminster Abbey—The exhibition at the Hall—The Doctor agrees to go in
the carriage of the “jolly fat dame”—Mr. Melody objects—The Doctor’s
melancholy—Indians stop the bus to talk with Lascars—Make them presents
of money—Indians discover chickabobboo-ags (gin-palaces)—and ladies
lying down in their carriages reading books—Chim-e-gotch-ees (or fish)—
Jim’s story of “Fish”—Experiments in mesmerism—Wash-ka-mon-ya (Jim)
mesmerized—The Doctor’s opinions on mesmerism—Ioways in Lord’s Cricket-
ground—Archery and ball-playing—Encampment—Wigwams—Indians invited
by Mrs. Lawrence to Ealing Park—Their kind reception—Their Royal
Highnesses the Duke and Duchess of Cambridge—The Princess Mary—The
Duchess of Gloucester—The Hereditary Grand Duke and Duchess, and other
distinguished guests—Amusements—Beautiful grounds—Indians dine on the
lawn—Roast beef and plum-pudding—Chickabobboo—Alarm of the parrots—
Doctor’s superstition—Chickabobboo explained—Speech of the War-chief—
Taking leave—Fright of the poor birds—Handsome presents—Conservatory—
The Doctor’s ideas of it—Indians visit Surrey Zoological Gardens—Fright of
the birds and animals—Indians sacrifice tobacco to the lion and the rattle-
snakes.

Mr. Melody, feeling the high importance of the charge of these


fourteen wild people intrusted to his hands by the Government while
they were to see the sights of a foreign country, and feeling the
strongest attachment to them personally, was stimulated to every
exertion by which he could properly open their eyes to the benefits of
civilization, and consequently was inquiring from day to day “what
shall be shown them next?”
I had also, with feelings of the highest respect for the chiefs of the
nation, knowing them to be of the party, enlisted my warmest
exertions in their behalf, and resolved to render them, in all ways I
could, the aid that was due from me for their hospitality which
benefited me when I was in their country.
With these views we continued our omnibus in driving them about
the City and country, and one or the other of us was almost daily
accompanying them to some institution or public works from which
they might derive some useful information. To these they generally
went together and in their native dresses, but there were others
where their costumes and their paint would render them too
conspicuous, and for such purposes two or three suits of clothes,
beaver hats and wigs, became necessary for such a number as
wished at any time to look further (and unobserved) into the arcana
and hidden mysteries of the great metropolis. And the reader will be
ready to exclaim with me, that the field before us was a vast and
boundless one.
The two most ambitious to profit by such adventures were “Jim” (as I
have before denominated him) and the “Doctor:” the first, from a
peculiar faculty he had of learning the English language (in which he
was making daily progress), and a consequent insatiable desire to
see and learn the modes, and everything he could, of white people,
excepting their religion; and the second, from an indomitable desire
to look in everywhere and upon everything, more for the pleasure of
gratifying a momentary curiosity, and enjoying a temporary smile,
than from any decided ambition to carry home and adopt anything,
unless it might be a vapour-bath, or something of the kind, in the
way of his profession.
In frock-coats and beaver hats, and boots, with a large stick or an
umbrella under the arm, and the paint all washed off, there was not
much in the looks of these two new-fangled gentlemen to attract the
public gaze or remark; and consequently little in the way of the sights
and treasures of London being opened to their view.
From the time that this expedient was adopted, our avocations
became more diversified and difficult; our anxieties and cares
increased, and with them our amusement: for with Melody the sights
of London were as yet prospective; and with me, whether old or new,
I met them with an equal relish with my unsophisticated brethren
from the wilderness.
The amusement of “trying on” and “getting the hang” of the new
dresses made merriment enough for the party for one day; and all
but these two were quite willing to forego all the pleasures they could
afford, rather than cover their cool and naked heads with beaver
hats, their shoulders with frock-coats, and substitute for their soft
and pliant mocassins and leggings of buckskin, woollen pantaloons
and high-heeled boots. The two wiseacres, however, who had
adopted them were philosophers, and knew that they were only for
certain occasions, after which they were to be dropped off, and their
limbs “at home again” in their light and easy native dresses. They
were obliged, on such occasions (to be in keeping), to leave their
long and ornamented pipes and tomahawks behind, and (not to lose
the indispensable luxury of smoking) to carry a short and handy
civilized pipe, with their tobacco, and a box of lucifers, in their
pockets.
Reader, pray don’t try to imagine what a figure these two copper-
coloured “swells” cut, when they first sallied forth in their new attire,
for it will be in vain: but behold them and me, in the future pages of
this book, and when their dresses had got to work easy, profiting by
gazing upon the wonders and glories of civilization, which we never
otherwise could have beheld together.
As one of the first fruits of the new expedient (and while the subject
was fresh and revolving in the minds of all), there was now a chance
of gratifying the Doctor’s desire to see the modes and places of
worship of some of the different denominations of religion, of which
he had heard so much, from Daniel and others, within the few days
past. These visits were their first attempts in their assumed
characters, and were mostly made in the company of Mr. Melody or
Jeffrey, and without any amusing results either for the congregations
or the Ioways, save an incident or two, such as must be expected in
the first experiments with all great enterprises. The Doctor had been
told that when he entered the Protestant Church, he must take his
hat off at the door, and had practised it before he started; but, seeing
such an immense number of ladies, he had unfortunately forgot it,
and being reminded of it when he had been placed in his seat, his
wig came off with it, exposing, but a moment however, his scalp-lock
and the top of his head, where he had not deemed it necessary to
wash off the red paint.
In the Methodist chapel, where these two queer fellows had ventured
one day with Daniel, the sermon was long and tedious, and there
was nothing observed curious excepting a blue smoke rolling up over
the top of the pew, where the Doctor’s pipe had been lit, and his
head sunk down between his knees; and one other occurrence, that
afterwards happened in the heat of the exhortation from the pulpit,
and much to the amusement of the Doctor and Jim, of a young
woman, in their immediate vicinity, who began to groan, then to sing,
and at length tumbled down from her seat upon the floor. The Doctor
thought at first she was very sick, and wondered there was no
physician there to bleed her; but when Daniel told him what was the
matter, the old man smiled, and often talked about it afterwards.
I took the whole party through Westminster Abbey and St. Paul’s,
where they stood and contemplated in amazement the works of
human hands, so entirely beyond their comprehension that they
returned in reserved and silent contemplation.
Returning again to the Exhibition-room at the Egyptian Hall, several
evenings of which have passed by without mention, but much in the
same way, we find the same excitement and applause, and the “jolly
fat dame” at the end of the platform, nightly receiving the Doctor’s
impressive smiles, which are constantly ready for her; and which by
this time, aided by the continued coldness of the Roman-nose, were
making visible inroads upon her tender affections. She had had, it
seemed, on this evening, some conversation with the Doctor, through
the interpreter, who had heretofore studiously kept out of the way,
and she had invited the Doctor to ride to her house in her carriage,
after the exhibition was over, believing that he would be able to find
in her garden, some roots which he was in great distress to find, and
that she would bring him home again safe. Mr. Melody objected to
this, which seemed to puzzle the fair dame, and to throw the Doctor
into a profound melancholy and dejection.
This rebuff from Mr. Melody was so unexpected and so provoking,
when she had so nearly accomplished her object, that the good lady
passed out of the room earlier than usual, and tossed her head about
with her ostrich plumes as she passed along in the crowd, without
having the heart to stop and speak a few words to Daniel, as she had
been in the habit of doing. Mr. Melody retired with the Indians, and I
remained after the crowd had left, at the solicitation of a party of
ladies, who had sent me their card and wished to see me after the
exhibition was over. The room being nearly emptied, I saw a party of
several fashionably-dressed ladies at the further end of the room,
examining the paintings on the walls. In advancing towards them, the
one who seemed to be the leader of the party turned around and
exclaimed, “Oh, here comes Mr. Catlin, I believe?” “Yes, Madam, I am
Mr. Catlin.” “Oh, I am so happy to have the honour of seeing you, Sir,
and of speaking to you—you have made all these paintings?” “Yes.”
“These Indians are curious fellows, and well worth seeing, but I
consider you ten times more of a curiosity. Look here, ladies, here’s
Mr. Catlin, the very man that I have so often told you about. Dear
me, what dangers and hardships you must have been through! Oh, I
do think you are one of the wonders of the world—and not a grey
hair in your head yet! My dear Sir, I know your whole history— you’d
scarcely believe it—I know it ’like a book,' as they say. I recollect the
very day when you started for India, and I have followed you the
whole way—I have your book—I bought several copies to give to my
friends; I have read every word of it over and over again—and, oh!
it’s wonderful—it’s charming—one can’t stop in it—there’s no stopping
place in it. By the way, I don’t suppose you were down much in the
neighbourhood of Chusan (I’ve got a nephew there—a fine fellow—
he’s a surgeon). I suppose you kept pretty much back in the
mountains? You had no object in coming down about the coast; and
they have had rather hot work there.” “No, Madam, I had not the
slightest object to take me near Chusan—I kept a great way back.”
“That was right; oh, how judicious! Oh, I have read your interesting
work so often. By the way, these fellows are not from the coast—they
are from a great way back, I dare say?” “Yes, Madam, they are a
great way in the interior.” “I thought so, I knew so—I can tell, d’ ye
see—I can always tell a coaster. These are fine men—they grow tea,
I suppose, though?” “No, these people don’t grow tea.” “Ah, well, it’s
late, we won’t take up your time; but I have been so happy to have
seen you—glad, glad to see you home alive to your native soil, and
out of that plagued India. Good night.” “Good night, ladies.”
As they left me, I turned round, and met a poor fellow approaching
me on one leg and a pair of crutches, and his wife holding on to his
arm. He said he had been waiting some time to have the honour of
speaking to me before he left, having heard my name pronounced.
He told me he lived at Woolwich, where he held some situation for
life, as he had lost his leg in the service of his country, and it was a
good living for him, luckily, though he had been so unfortunate as to
lose his leg.
“My wife and I (said he) ave long eard of this extro’nary hexibition,
and she as often hax’d me to come to see it; and though we ave
been off and hon about it a great many times, we never got off
together until this hafter-noon—it’s a wonderful sight, sir, hand we
are appy to ave seen you halso.”
I thanked the poor fellow, and asked him how he lost his leg.
“It was done by the kick of a orse, Sir.”
“But your leg has been taken off above your knee.”
“Yes, Sir, the bone was broken, hand it ad to be hamputated.”
“It must have been very painful!”
“Ah, hit urt a little; though as for the pain of hamputation, I woudn’t
give a penny for it: but the loss of my leg is worth a great deal to
me; it’s hall ealed up now, Sir, though it’s very hunandy.”
This simple and unfortunate man and his very pretty little wife left
me, and I repaired to the Indians’ rooms in St. James’s Street, where
I found them finishing their suppers and taking their chickabobboo.
Here was in readiness a long catalogue of the adventures of the day
—of things they had seen in their drive, &c., to be talked over, as well
as the cruel jokes to be listened to, which they were all passing upon
the poor Doctor, for the sudden failure of his prospects of digging
roots in the fair dame’s garden.
There were many subjects of an amusing nature talked over by these
droll fellows during the pipes of this evening, and one of the themes
for their comments was the drive which we had given them in two
open carriages through Hyde Park, at the fashionable hour. They
decided that “the Park, along the banks of the Serpentine, reminded
them of the prairies on the shores of the Skunk and the Cedar rivers
in their own country; and in fact, that some parts of it were almost
exactly the same.” They were amused to see many of the ladies lying
down as they rode in their carriages; and also, that many of the great
chiefs, pointed out to them riding on horseback, “didn’t know how to
ride—that they were obliged to have a man riding a little behind them
to pick them up if they should fall off.”
Jim, who was in an unusual good humour this evening, either from
the effects of his chickabobboo or from some fine present he might
have received in the room, seemed to be the chief “spokesman” for
the evening, and for the purpose of assisting his imagination or
aiding his voice had laid himself flat upon his back upon his robe,
which was spread upon the floor. His loquacity was such, that there
was little else for any of us to do than sit still and excessively laugh at
the dryness of his jokes, and his amusing remarks upon the things
they had seen as they were taking their ride on this and past
mornings. He had now got, as has been said, a facility of using
occasional words of English, and he brought them in once in a while
with the most amusing effect.
He said they had found another place where there were two more
Ojibbeway Indians (as he called them), Lascars. sweeping the
streets; and it seems that after passing them they had ordered their
bus to stop, and called them up and shook hands, and tried to talk
with them. They could speak a few words in English, and so could
Jim: he was enabled to ask them if they were Ojibbeways, and they
to answer, “No, they were Mussulmen.” “Where you live?” “Bombay.”
“You sweep dirt in the road?” “Yes,” “Dam fool!” Jim gathered a
handful of pennies and gave them, and they drove off.
It seemed that in their drive this day, Jim and the Doctor had both
rode outside, which had afforded to Jim the opportunity of seeing to
advantage, for the first time. the immense number of “gin palaces,”
as they passed along the streets; and into which they could look from
the top of the bus, and distinctly see the great number of large kegs,
and what was going on inside. The Doctor had first discovered them
in his numerous outside rides, and as he was not quite sure that he
had rightly understood them, hearing that the English people
detested drunkards so much, he had not ventured to say much about
them. He had been anxious for the corroboration of Jim’s sharper
eyes, and during this morning they had fully decided that the
hundreds of such places they were in all directions passing, were
places where people went to drink chickabobboo, and they were
called chickabobbooags. The conversation of Jim and the Doctor
enlarged very much on this grand discovery, and the probable effects
they had upon the London people. They had seen many women, and
some of them with little babies in their arms, standing and lying
around them, and they were quite sure that some of those women
were drunk. Jim said that he and the Doctor had counted two or
three hundred in one hour. Some of the party told him he had made
his story too big, so he said he and the Doctor next day would mark
them down on a stick. Jim said there was one street they came
through, where he hoped they would never drive them again, for it
made their hearts sore to see so many women and little children all in
dirty rags: they had never seen any Indians in the wilderness half so
poor, and looking so sick. He was sure they had not half enough to
eat. He said he thought it was wrong to send missionaries from this
to the Indian country, when there were so many poor creatures here
who want their help, and so many thousands as they saw going into
the chickabobbooags to drink fire-water.
He said they came through a very grand street, where every thing
looked so fine and splendid in the windows, and where the ladies
looked so beautiful in their carriages, many of them lying quite down,
and seemed as if they were very rich and happy; and some of them
lay in their carriages, that were standing still, so as to let them read
their books. And in this same grand street they saw a great many
fine-looking ladies walking along the sides of the roads, and looking
back at the gentlemen as they passed by them. These ladies, he and
the Doctor observed, looked young, and all looked very smiling, and
they thought they wanted husbands. A great deal, Jim said, they had
seen of these ladies as they were every day looking out of their own
windows in St. James’s Street. A great many of these women, he
said, behave very curious; he said he didn’t know for certain but
some of these might be chimegotches. This excited a tremendous
laugh with the Doctor and several of the young men, and made some
of the women smile, though it was rather hushed by the chiefs as an
imprudent word for Jim to apply in the present case. This did little,
however, to arrest the effects of Jim’s joke, and he continued with
some further ingenious embellishments, which set the chiefs into a
roar, and Jim then kept the field. Melody and myself laughed also, not
at the joke, for we did not understand it, but at their amusement,
which seemed to be very great, and led us to inquire the meaning of
chimegotches. “Fish,” said Jim, “fish!” We were still at a loss for the
meaning of his joke; and our ignorance being discovered, as well as
our anxiety to know, they proposed that Jim should relate the story
of Chimegotches, or “Fish.” Some one was charging and lighting the
pipe in the mean time, which was handed to him, as he rose and
took a whiff or two, and then, resuming his former position, flat upon
his back, he commenced—
“When the great Mississippi river was a young and beautiful
stream, and its waters were blue and clear, and the Ioways lived on
its banks, more than a thousand snows since, Net-no-qua, a young
man of great beauty, and son of a great chief, complained that he
was sick. His appetite left him, and his sleep was not good. His
eyes, which had been like those of the war-eagle, grew soft and
dim, and sunk deep in his head. His lips, that had been the music
for all about him, had become silent; his breast, that had always
been calm, was beating, and deep sighs showed that something
was wrong within. O-za-pa, whose medicine was great, and to
whom all the plants and roots of the prairies were known, was
quite lost; he tried all, and all was in vain; the fair son of the chief
was wasting away, as each sweet breath that he breathed went off
upon the winds, and never came back to him. Thus did Net-no-
qua, the son of Ti-ah-ka, pine away. The medicine man told him at
last that there was but one thing that could cure him, and that was
attended with great danger. In his dream a small prairie snake had
got upon a bush, and its light, which was that of the sun, opened
his eyes to its brightness, and his ears to its words: ‘The son of Ti-
ah-ka grieves—this must not be—his breast must be quiet, and his
thoughts like the quiet waters of the gliding brook; the son of Ti-
ah-ka will grow like the firm rocks of the mountain, and the chiefs
and warriors, who will descend from him, will grow like the
branches of the spreading oak.’ The medicine man said to the son
of Ti-ah-ka that he must now take a small piece of the flesh from
his side for his bait, and in a certain cove on the bank of the river,
the first fish that he caught was to be brought to his wigwam
alone, under his robe, and she, whose blood would become warm,
would be to him like the vine that clings around and through the
branches of the oak: that then his eyes would soon shine again like
those of the eagle; the music of his lips would soon return, and his
troubled breast would again become calm, his appetite would be
good, and his sleep would be sweet and quiet like that of a babe.
“Net-no-qua stood upon a rock, and when the hook, with a piece of
his side, lay upon the water, the parting hair of Lin-ta (the river-
born) was seen floating on the water, and its black and oily tresses
were glistening in the sun as the water glided off from them; and
her lips were opening to enclose the fatal hook that raised her
beautiful breasts above the water. Her round and delicate arms
shone bright with their beauty as she extended them to the shore,
and the river shed its tears over her skin as her beautiful waist
glided through its surface, above which the strong and manly arm
of Net-no-qua was gently raising her. The weeping waves in
sparkling circles clung around her swelling hips and pressing knees,
until the folding robe of the son of Ti-ah-ka was over the wave and
around her bending form. One hand still held her slim and tapering
fingers, and with the other he encompassed her trembling form, as
their equal steps took them from the shore and brought them to
the wig-wam of Net-no-qua. His silent house was closed from the
footsteps of the world; her delicate arms clung around the neck of
the son of the chief, and her black and glossy tresses fell over and
around his naked shoulders and mingled with his own. The same
robe embraced them both, and her breath was purer than the blue
waves from which she came. Their sleep was like the dreams of
the antelope, and they awoke as the wild rose-buds open amidst
the morning dew; the breast of Net-no-qua was calm, his eyes
were again like the eyes of the eagle, his appetite was keen, and
his lips sounded their music in the ears of Lin-ta. She was lovely,
she was the wife of the son of the chief, and like the vine that
clings around and through the branches of the oak, did she cling to
Net-no-qua. They were happy, and many have been the
descendants that have sprung from the dreams of the son of Ti-ah-
ka and the beautiful Lin-ta (the river-born).
“O-ne-ak’n was the brother of Net-no-qua, and Di-ag-gon was his
cousin: and they were sick; and they sat upon the rock in the cove
in the river: and the two sisters of Lin-ta shone as they lifted their
graceful forms above the wave, and their beautiful locks spread as
they floated on the surface. The two young warriors sighed as they
gazed upon them. The two sisters embraced each other as they
glided through and above the waves. They rose to full view, and
had no shame. The river ’shed no tears, nor did the sparkling
waves hang in circles about their swelling hips and pressing knees;'
and as they sank, they beckoned the two young warriors, who
followed them to their water-bound caves. They stole back in the
morning, and were ashamed and sick. Their tongues were not
silent, and others went. The two sisters again showed their lovely
forms as they glided above the water, and they beckoned all who
came to their hidden caves, and all came home in the morning sick
and sad, while every morning saw the son of the chief and his
river-born Lin-ta calm and bright as the rising sun. Shame and fear
they knew not, but all was love and happiness with them; very
different were the sisters of Lin-ta, who at length ventured from
their caves at night, and strolled through the village; they were
hidden again at the return of the light. Their caves were the resorts
of the young men, but the fair daughters of Lin-ta knew them not.
“Such was the story of Lin-ta (the river-born); she was the loved of
her husband, and the virtuous mother of her children. Her beautiful
sisters were the loved of all men, but had no offspring. They live in
their hidden caves to this day, and sometimes in the day as well as
in the night are seen walking through the village, though all the
Indians call them Chim-ee-gotch-es, that is, Cold-bloods, or Fish.”
Jim got a round of applause for his story, though the Doctor thought
he had left out some of the most essential and funny parts of it. Jim,
however, seemed well content with the manner in which it was
received, and continued to remark that he and the Doctor had come
to the conclusion that those beautiful young women, that they saw
looking back at the gentlemen in the streets, as well as those who
were standing in front of their windows, and bowing to them, and
kissing their hands every day, must be “fish;” and that in the great
village of London, where so much chickabobboo is drunk, there must
be a great number of “fish.” And they thought also that some of
these they had seen in the Egyptian Hall when they were giving their
dances.
The above and other critiques of Jim upon London modes seemed to
the chiefs to be rather too bold, and an impolitic position for Jim to
take; and whilst their reprimands were being passed upon him, the
train of humour he had happened to get into on that night turned all
their remarks into jokes, and they were obliged to join in the
irresistible merriment he produced on this occasion, merely from his
having taken (as his wife had refused it on this evening as it was just
now discovered) the additional mug of his wife’s chickabobboo.
Much merriment was produced amongst the Indians about this time
by an appointment that had been made to see some experiments in
mesmerism, to be performed by a Dr. M—— at the Indians’ rooms.
The Doctor was received at the appointed hour, and brought with him
a feeble and pale-looking girl of 14 or 15 years of age to operate
upon. This had taken the Indians rather by surprise, as no one had
fully explained the nature of the operations to them. I got Jeffrey,
however, to translate to them, as near as he could, the nature of this
extraordinary discovery, and the effects it was to produce; and the
doors being closed, and the young woman placed in a chair, the
mesmeriser commenced his mysterious operations. I had instructed
the Indians to remain perfectly still and not to laugh, lest they might
hinder the operator, and prevent the desired effect. With one knee
upon the floor, in front of her, and placing both of his extended
thumbs (with his hands clenched) just in front of her two eyebrows,
he looked her steadily in the face. This eccentric position and
expression disposed Jim to laugh, and though he covered his huge
mouth with his hand, and made no noise, still the irresistible
convulsions in his fat sides shook the floor we were standing on; and
the old Doctor at the same time, equally amused, was liable to do
less harm, for all his smiles and laughter, however excessive, were
produced by the curious machinery of his face, and never extended
further down than the chin or clavicles. The little patient, however,
was seen in a few minutes to be going to sleep, and at length fell
back in the chair, in the desired state of somnambulism. The operator
then, by mesmeric influences, opened her eyes, without touching
them, and without waking her, and by the same influence closed
them again. In the same way he caused her hand to close, and none
of us could open it. Here our Doctor, who tried it, was quite at a
stand. He saw the fingers of the operator pass several times in front
of it, and its muscles relaxed—it opened of itself. He then brought, by
the same influence, her left arm to her breast, and then the right,
and challenged the strength of any one in the room to unbend them.
This was tried by several of us, but in vain; and when his fingers
were passed a few times lightly over them, they were relaxed and
returned to their former positions. By this time the Indian women,
with their hands over their mouths, began to groan, and soon left the
room in great distress of mind. The chiefs, however, and the Doctor
and Jim, remained until the experiments were all tried, and with
unaccountable success. The operator then, by passing his fingers a
few times over the forehead of his patient, brought her gradually to
her senses, and the exhibition ended. The convulsions of Jim’s broad
sides were now all tempered down into cool quiet, and the knowing
smiles of the old Doctor had all run entirely off from, and out of, the
furrows of his face, and a sort of painful study seemed to be
contracting the rigid muscles that were gathering over them.
No. 12.

The chiefs pronounced the unaccountable operation to be the


greatest of medicine, and themselves quite satisfied, as they retired;
but the old Doctor, not yet quite sure, and most likely thinking it a
good thing for his adoption among the mysteries of his profession in
his own country, was disposed to remain, with his untiring companion
Jim, until some clue could be got to this mystery of mysteries. With
this view he had the curiosity of feeling the little girl’s pulse, of
examining and smelling the operator’s fingers, &c., and of inquiring
whether this thing could be done by any others but himself; to which
I replied, that it was now being done by hundreds all through the
country, and was no secret. The charm had then fled—it had lost all
its value to the old Doctor. The deep thoughts ceased to plough his
wrinkled face, and his self-sufficient, happy smiles were again playing
upon his front. His views were evidently changed. Jim caught the
current of his feelings, and amusement was their next theme. The old
Doctor “thought that Jim could easily be frightened,” and would be a
good subject. It was proposed that Jim should therefore take the
chair, and it was soon announced to the squaws, and amongst them
to his wife, that Jim had gone to sleep, and was mesmerised. They all
flew to the room, which upset the gravity of his broad mouth, and,
with its movements, as a matter of course, the whole bearing of his
face; and the operator’s fingers being withdrawn from his nose, he
left the chair amidst a roar of laughter. It was then proposed that the
old Doctor should sit down and be tried, but he resisted the
invitation, on the grounds of the dignity of his profession, which he
got me to explain to the medical man, whom he was now evidently
disposed to treat rather sarcastically, and his wonderful performance
as a piece of extraordinary juggling, or, at least, as divested of its
supposed greatest interest, that of novelty. He told him “that there
was nothing new or very wonderful in the operation, that he could
discover; it was no more than the charm which the snakes used to
catch birds; and the more frightful and ugly a man’s face was, the
better he could succeed in it. He had no doubt but many ill-looking
men amongst white people would use it as a mode of catching pretty
girls, which they could not otherwise do, and therefore it would be
called amongst white people a very useful thing.”
“All the medicine-men (said he) in the Indian country have known for
many years how to do the same thing, and what the white people
know of it at this time they have learned from the Indians; but I see
that they don’t yet half know how to do it; that he had brought a
medicine dress all the way with him for the very purpose, and if the
mesmeriser would come the next morning at 9 o’clock, he should see
him with it on, and he would engage to frighten any white lady to
sleep in five minutes who would take a good look at him without
winking or laughing.” The mesmeriser did not come, though the
Doctor was on the spot and ready. (Plate No. 12.)
An event which they had long been looking for with great solicitude
took place about this time—the prorogation of Parliament, which
afforded the poor fellows their only opportunity of seeing the Queen.
They were driven off in good season in their bus, and succeeded in
getting the most favourable view of the Queen and the Prince as they
were passing in the state-carriage; and, to use their own words for it,
“The little Queen and the Prince both put their faces quite out of their
carriage of gold to look at us and bow to us.” There is no doubt but
by the kindness of the police they were indulged in a favourable
position and had a very satisfactory view of Her Majesty the Queen,
and it is equally certain that they will never cease to speak of the
splendour of the effect of the grand pageant as long as they live.
The nightly excitements and amusements going on at the Egyptian
Hall were increasing the public anxiety to see these curious people
more at large, and we resolved to procure some suitable ground for
the purpose, where their active limbs could be seen in full motion in
the open air, as they are seen on their native prairies with their ball-
sticks, in their favourite game of the ball, and the use of their bows
and arrows, all of which they had brought with them, but could not
use in their amusements at the Hall. Their dances, &c., were,
however, to be kept up as usual, at night; and for their afternoon
exercises in the open air, an arrangement was made for the use of
“Lord’s Cricket Ground,” and on that beautiful field (prairie, as they
called it) they amused thousands, daily, by their dances, archery, and
ball-playing.[18] For this purpose an area of an acre or two was
enclosed by a rope, and protected for their amusements by the
police. To this the visitors advanced on every side, and seemed
delighted with their rude appearance and native sports. This
arrangement afforded the Indians the opportunity of showing their
games and amusements to the greatest advantage, and also of
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.

More than just a book-buying platform, we strive to be a bridge


connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.

Join us on a journey of knowledge exploration, passion nurturing, and


personal growth every day!

ebookbell.com

You might also like