Programming in Lua 2nd Edition Roberto Ierusalimschy pdf download
Programming in Lua 2nd Edition Roberto Ierusalimschy pdf download
https://ebookfinal.com/download/programming-in-lua-2nd-edition-
roberto-ierusalimschy/
https://ebookfinal.com/download/programming-in-lua-3rd-edition-
roberto-ierusalimschy/
https://ebookfinal.com/download/beginning-lua-programming-1st-edition-
jung/
https://ebookfinal.com/download/love-for-lua-game-programming-1st-
edition-akinlaja/
https://ebookfinal.com/download/programming-in-haskell-2nd-edition-
graham-hutton/
C Programming in Linux 2nd Edition David Haskins
https://ebookfinal.com/download/c-programming-in-linux-2nd-edition-
david-haskins/
https://ebookfinal.com/download/elements-of-programming-interviews-in-
java-2nd-edition-adnan-aziz/
https://ebookfinal.com/download/programming-ios-5-2nd-edition-matt-
neuburg/
https://ebookfinal.com/download/asynchronous-android-programming-2nd-
edition-helder-vasconcelos/
https://ebookfinal.com/download/under-her-spell-roberto-rossellini-in-
india-1st-edition-dileep-padgaonkar/
Programming in Lua 2nd Edition Roberto Ierusalimschy
Digital Instant Download
Author(s): Roberto Ierusalimschy
ISBN(s): 9788590379829, 8590379825
Edition: 2
File Details: PDF, 1.58 MB
Year: 2006
Language: english
Programming ROBERTO IERUSALIMSCHY
in
Lua
2nd
edition
Lua.org
Roberto Ierusalimschy
PUC-Rio, Brazil
Lua.org
Rio de Janeiro
ISBN 85-903798-2-5
Book cover and illustrations by Dimaquina. Lua logo design by Alexandre Nako.
Typesetting by the author using LATEX.
Although the author used his best efforts preparing this book, he assumes no
responsibility for errors or omissions, or for any damage that may result from
the use of the information presented here. All product names mentioned in this
book are trademarks of their respective owners.
Preface xiii
I The Language 1
1 Getting Started 3
1.1 Chunks 4
1.2 Some Lexical Conventions 5
1.3 Global Variables 6
1.4 The Stand-Alone Interpreter 7
3 Expressions 19
3.1 Arithmetic Operators 19
3.2 Relational Operators 20
3.3 Logical Operators 21
3.4 Concatenation 22
3.5 Precedence 22
3.6 Table Constructors 22
vii
4 Statements 27
4.1 Assignment 27
4.2 Local Variables and Blocks 28
4.3 Control Structures 30
4.4 break and return 34
5 Functions 35
5.1 Multiple Results 36
5.2 Variable Number of Arguments 39
5.3 Named Arguments 42
9 Coroutines 73
9.1 Coroutine Basics 73
9.2 Pipes and Filters 76
9.3 Coroutines as Iterators 79
9.4 Non-Preemptive Multithreading 81
10 Complete Examples 87
10.1 Data Description 87
10.2 Markov Chain Algorithm 91
Index 299
When Waldemar, Luiz, and I started the development of Lua, back in 1993, we
could hardly imagine that it would spread as it did. Started as an in-house
language for two specific projects, currently Lua is widely used in all areas that
can benefit from a simple, extensible, portable, and efficient scripting language,
such as embedded systems, mobile devices, web servers, and, of course, games.
We designed Lua, from the beginning, to be integrated with software written
in C and other conventional languages. This integration brings many benefits.
Lua is a tiny and simple language, partly because it does not try to do what C is
already good for, such as sheer performance, low-level operations, and interface
with third-party software. Lua relies on C for these tasks. What Lua does
offer is what C is not good for: a good distance from the hardware, dynamic
structures, no redundancies, ease of testing and debugging. For this, Lua has
a safe environment, automatic memory management, and good facilities for
handling strings and other kinds of data with dynamic size.
A great part of the power of Lua comes from its libraries. This is not by
chance. After all, one of the main strengths of Lua is its extensibility. Many fea-
tures contribute to this strength. Dynamic typing allows a great degree of poly-
morphism. Automatic memory management simplifies interfaces, because there
is no need to decide who is responsible for allocating and deallocating memory,
or how to handle overflows. Higher-order functions and anonymous functions
allow a high degree of parameterization, making functions more versatile.
More than an extensible language, Lua is also a glue language. Lua sup-
ports a component-based approach to software development, where we create
an application by gluing together existing high-level components. These com-
ponents are written in a compiled, statically typed language, such as C or C++;
Lua is the glue that we use to compose and connect these components. Usually,
the components (or objects) represent more concrete, low-level concepts (such as
widgets and data structures) that are not subject to many changes during pro-
gram development, and that take the bulk of the CPU time of the final program.
Lua gives the final shape of the application, which will probably change a lot
during the life cycle of the product. However, unlike other glue technologies,
Lua is a full-fledged language as well. Therefore, we can use Lua not only to
xiii
glue components, but also to adapt and reshape them, and to create whole new
components.
Of course, Lua is not the only scripting language around. There are other
languages that you can use for more or less the same purposes. But Lua offers
a set of features that makes it your best choice for many tasks and gives it a
unique profile:
Extensibility: Lua’s extensibility is so remarkable that many people regard Lua
not as a language, but as a kit for building domain-specific languages. Lua
has been designed from scratch to be extended, both through Lua code and
through external C code. As a proof of concept, Lua implements most of
its own basic functionality through external libraries. It is really easy to
interface Lua with C/C++, and Lua has been used integrated with several
other languages as well, such as Fortran, Java, Smalltalk, Ada, C#, and
even with other scripting languages, such as Perl and Ruby.
Simplicity: Lua is a simple and small language. It has few (but powerful)
concepts. This simplicity makes Lua easy to learn and contributes to its
small size. Its complete distribution (source code, manual, plus binaries
for some platforms) fits comfortably in a floppy disk.
Efficiency: Lua has a quite efficient implementation. Independent benchmarks
show Lua as one of the fastest languages in the realm of scripting (inter-
preted) languages.
Portability: When we talk about portability, we are not talking about running
Lua both on Windows and on Unix platforms. We are talking about run-
ning Lua on all platforms we have ever heard about: PlayStation, XBox,
Mac OS-9 and OS X, BeOS, QUALCOMM Brew, MS-DOS, IBM main-
frames, RISC OS, Symbian OS, PalmOS, ARM processors, Rabbit proces-
sors, plus of course all flavors of Unix and Windows. The source code for
each of these platforms is virtually the same. Lua does not use conditional
compilation to adapt its code to different machines; instead, it sticks to
the standard ANSI (ISO) C. This way, you do not usually need to adapt it
to a new environment: if you have an ANSI C compiler, you just have to
compile Lua, out of the box.
Audience
Lua users typically fall into three broad groups: those that use Lua already
embedded in an application program, those that use Lua stand alone, and those
that use Lua and C together.
Many people use Lua embedded in an application program, such as CGILua
(for building dynamic Web pages) or a game. These applications use the Lua–
C API to register new functions, to create new types, and to change the behavior
of some language operations, configuring Lua for their specific domains. Fre-
quently, the users of such applications do not even know that Lua is an inde-
pendent language adapted for a particular domain; for instance, CGILua users
tend to think of Lua as a language specifically designed for the Web; players of
a specific game may regard Lua as a language exclusive to that game.
Lua is useful also as a stand-alone language, not only for text-processing
and one-shot little programs, but increasingly for medium-to-large projects, too.
For such uses, the main functionality of Lua comes from libraries. The stan-
dard libraries offer pattern matching and other functions for string handling.
(We may regard the stand-alone language as the embedding of Lua into the
domain of string and text-file manipulation.) As Lua improves its support for li-
braries, there has been a proliferation of external packages. The Kepler project
(http://www.keplerproject.org), for instance, is a Web development platform
for Lua that offers packages for page generation, database access, LDAP, XML,
and SOAP. The LuaForge site (http://www.luaforge.net) offers a focal point
for many Lua packages.
Finally, there are those programmers that work on the other side of the
bench, writing applications that use Lua as a C library. Those people will
program more in C than in Lua, although they need a good understanding of
Lua to create interfaces that are simple, easy to use, and well integrated with
the language.
This book has much to offer to all these people. The first part covers the
language itself, showing how we can explore all its potential. We focus on
different language constructs and use numerous examples to show how to use
them for practical tasks. Some chapters in this part cover basic concepts, such
as control structures, but there are also advanced topics, such as iterators and
coroutines.
The second part is entirely devoted to tables, the sole data structure in Lua.
Its chapters discuss data structures, persistence, packages, and object-oriented
programming. There we will unveil the real power of the language.
The third part presents the standard libraries. This part is particularly
useful for those that use Lua as a stand-alone language, although many other
applications also incorporate all or part of the standard libraries. This part
devotes one chapter to each standard library: the mathematical library, the table
library, the string library, the I/O library, the operating system library, and the
debug library.
Finally, the last part of the book covers the API between Lua and C, for those
that use C to get the full power of Lua. This part necessarily has a flavor quite
different from the rest of the book. There we will be programming in C, not
in Lua; therefore, we will be wearing a different hat. For some readers, the
discussion of the C API may be of marginal interest; for others, it may be the
most relevant part of this book.
First, I have updated the whole book to Lua 5.1. Of particular relevance is
the chapter about modules and packages, which was mostly rewritten. I also
rewrote several examples to show how to benefit from the new features offered
by Lua 5.1. Nevertheless, I clearly marked features absent from Lua 5.0, so you
can use the book for that version too.
Second, there are several new examples. These examples cover graph rep-
resentation, tab expansion and compression, an implementation for tuples, and
more.
Third, there are two complete new chapters. One is about how to use multiple
states and multiple threads from C; it includes a nice example of how to imple-
ment a multi-process facility for Lua. The other is about memory management
and how to interact with memory allocation and garbage collection.
After the release of the first edition of Programming in Lua, several publish-
ers contacted us showing interest in a second edition. In the end, however, we
decided to self publish this second edition, as we did with the first one. Despite
the limited marketing, this avenue brings several benefits: we have total con-
trol over the book contents, we have freedom to choose when to release another
edition, we can ensure that the book does not go out of print, and we keep the
full rights to offer the book in other forms.
Other Resources
The reference manual is a must for anyone who wants to really learn a language.
This book does not replace the Lua reference manual. Quite the opposite, they
complement each other. The manual only describes Lua. It shows neither
examples nor a rationale for the constructs of the language. On the other hand,
it describes the whole language; this book skips over seldom-used dark corners of
Lua. Moreover, the manual is the authoritative document about Lua. Wherever
this book disagrees with the manual, trust the manual. To get the manual and
more information about Lua, visit the Lua site at http://www.lua.org.
You can also find useful information at the Lua users site, kept by the
community of users at http://lua-users.org. Among other resources, it offers
a tutorial, a list of third-party packages and documentation, and an archive of
the official Lua mailing list. You should check also the book’s web page:
http://www.inf.puc-rio.br/~roberto/pil2/
There you can find updated errata, code for some of the examples presented in
the book, and some extra material.
This book describes Lua 5.1, although most of its contents also apply to
Lua 5.0. The few differences between Lua 5.1 and Lua 5.0 are clearly marked in
the text. If you are using a more recent version, check the corresponding manual
for occasional differences between versions. If you are using a version older than
5.0, this is a good time to upgrade.
Acknowledgments
This book would be impossible without the help of several friends and institu-
tions. As always, Luiz Henrique de Figueiredo and Waldemar Celes, Lua co-
developers, offered all kinds of help.
Gavin Wraith, André Carregal, Asko Kauppi, Brett Kapilik, John D. Rams-
dell, and Edwin Moragas reviewed drafts of this book and provided invaluable
suggestions.
Lightning Source, Inc. proved a reliable and efficient option for printing and
distributing the book. Without them, the option of self-publishing the book
would probably not be an option.
Antonio Pedro, from Dimaquina, patiently endured my shifting opinions and
produced the right cover design.
Norman Ramsey kindly provided useful insights about the best way to pub-
lish this book.
I also would like to thank PUC-Rio and CNPq for their continuous support
to my work.
Finally, I must express my deep gratitude to Noemi Rodriguez, for illumining
my life.
“D on’t stop to look behind you, but back water the best you
know how,” said Bob, seeing that his companion now and
then ceased his exertions, and faced about on his seat to gaze at the
canyon. “A few strong, steady strokes will put us all right.”
George dropped his oar into the water again, and pushed it from
him with all his strength, while Bob exerted himself to the utmost to
turn the boat around with the bow up stream.
For a long time the contest seemed doubtful, but gradually the
skiff began to turn, and George was beginning to take heart again,
when suddenly he heard an ominous snap behind him, followed by a
cry of alarm from Bob.
The cold chills crept all over him. With an indescribable feeling of
terror, he turned quickly about, and saw his companion holding the
stump of his oar in his hands, while his eyes were riveted on the
blade, which was floating off with the current.
The two boys looked at each other in silence, and then they looked
toward the mouth of the canyon.
“We are the victims of treachery, George,” said Bob, as soon as he
could speak. “Somebody removed this leather, sawed the oar half in
two, and then put the leather back again, just as it was before. Give
me your oar. If I can keep her broadside to the stream, perhaps the
current will throw us against the bank.”
He did not speak nor act like a boy who stood in momentary fear
of a violent death. His face was very pale, but his voice and his hands
were steady, and his words were uttered with the greatest calmness
and deliberation. He was as cool, apparently, as he was while
scudding before the gale in Dick Langdon’s water-logged canoe.
George, on the contrary, was almost paralyzed with terror. His
hands trembled violently, and while he was trying to unship his oar,
in order to pass it back to his companion, it slipped from his grasp
and fell into the water, and although they both made such frantic
efforts to recover it that they came within a hair’s breadth of
capsizing the heavily-loaded skiff, it floated quickly out of their
reach, carrying with it the last particle of their courage and all their
hopes of escape.
Being left at the mercy of the current, the skiff gradually veered
around, until her bow pointed down stream, and once more started
with terrific speed toward the yawning mouth of the canyon.
“It’s all up with us, George,” said Bob, still speaking with
wonderful calmness. “No power on earth can save us now from going
into that canyon. What are you going to do?” he added, as George
suddenly arose to his feet and began pulling off his coat.
“I am not going under without making the best fight I can,” replied
George, in desperation. “I am going to see if I can tow the boat to the
bank.”
“Sit down!” said Bob, earnestly, at the same time seizing his friend,
and pulling him back into his seat. “Are you tired of life? You
couldn’t stem this current for an instant. It will be time enough for us
to take to the water when the boat is smashed on the rocks in the
canyon.”
The boys were so completely stunned by their fearful peril, that
they had been blind and deaf to everything else; but now they turned
their eyes toward the shore, and saw that there was a terrible
commotion there.
When Ike saw the oar break in Bob’s hands, he had raised his voice
in frantic appeals for help, and soon succeeded in arousing all the
inmates of the ranch.
There were a dozen or more of them, all stalwart, courageous men,
who would have risked their lives any day to save Bob Howard.
But what could they do but stand helplessly there on the bank and
see the boat and its terrified occupants disappear in the canyon?
Some seemed to be urging one thing, and some another—all except
Uncle Bob and Arthur.
The former, who was of about as much use in an emergency as a
wooden man would have been, walked aimlessly up and down the
porch, calling loudly upon the herdsmen to do something and be
quick about it, while Arthur stood off by himself and gazed at the
flying boat as if he were fascinated.
The only ones who did not seem to lose their heads altogether were
the superintendent and Mr. Evans. As they ran swiftly along the bank
to keep pace with the boat, Bob saw that they were knotting together
a couple of long lariats.
“That’s our only chance, and it is a very slim one,” said he. “If we
can catch that rope when it is thrown to us, and they try to pull us up
against this current, they will draw the boat under.”
A moment later, a clear strong voice was heard above the excited
gabble of the terror-stricken herdsmen.
“Silence!” it cried. “I want to make those boys hear me. Bob, stand
by to catch this lasso, and we will haul you ashore. Are you all
ready?”
“Let it come!” shouted Bob in reply.
In an instant the herdsmen became silent and expectant. Mr.
Jacobs swung the coiled lariat around his head a few times and then
launched it out over the water. Anxious eyes watched it as it flew
through the air—not in a direct line for the boat, but several feet in
advance of it.
“It’s going wild!” cried George, in dismay.
“Don’t be alarmed,” was Bob’s encouraging response. “The current
will take us under it.”
And so it proved. The lariat fell squarely across the middle of the
boat, and the two boys threw themselves upon it and held fast to it.
A wild cheer burst from the men on shore, and was echoed by
George Edwards, who now looked upon their rescue as a thing
beyond a doubt. But Bob did not cheer, for he knew that the worst
was yet to come.
The lariat was slipping through his fingers in spite of all he could
do to prevent it; so he took a turn with it around the nearest thwart,
and looked up to see what Mr. Jacobs was doing.
He and Mr. Evans who held only about four feet of the other end of
the lariat in their hands, were running at the top of their speed
toward the grove, evidently with the intention of using one of the
trees as a snubbing-post.
“On shore, there,” shouted Bob, whose excitement was greater
than it had been at any time since his oar broke in his hands. “Make
another lariat fast to your end, so that you can give us plenty of slack
when the strain comes. If we don’t have a good deal of slack the
current will certainly carry us under, unless something breaks.
“All right!” shouted Mr. Jacobs. “Hold fast to your end, and we will
bring you ashore safe and sound.”
He turned and said something to one of the herdsmen, who darted
off toward the ranch. When Bob saw that he gave up all hope.
“It’s no use, old fellow,” said he despairingly. “If that man must go
to the house for another lariat before they can give us any more rope,
we might as well make up our minds that we’ve got to go into that
canyon. As this is the last chance, I shall have to bid you good-by. I’ll
say—”
Just then came the strain which Bob so much dreaded. The line
was suddenly whipped up out of the water and drawn as tight as a
bow-string, the spray flying from it in a perfect shower.
The stern of the skiff was jerked violently around toward the bank;
but, instead of swinging in, as everybody hoped and believed she
would, she careened until the water came in over the gunwale, and
she seemed to be on the very point of capsizing.
The boys threw themselves as far as they could over the opposite
gunwale to right her; but just then there was a loud crash, the line
was torn from their grasp, and Bob and his companion recovered
themselves just in time to see the thwart, to which the lariat had been
made fast, fly out of the boat and land in the water twenty feet
astern.
The men on shore stood aghast, and the boys clutched the
gunwales of the boat, which, after rocking from side to side for a
moment or two with the greatest violence, finally came to an even
keel, and shot toward the canyon with accelerated speed.
It was too late now to do anything more. Escape was impossible,
and even George had given up all hope of it, and nerved himself to
meet his fate. He and Bob had just time to take one short farewell
glance at their agonized friends on shore, and then the boat was
swept into the canyon, and darkness, impenetrable darkness, closed
about them!
No pen can describe the anguish of mind experienced by these two
boys as they sat there on the bottom of their boat, clinging to the
gunwales with a death-grip, holding their breath in suspense, and
waiting for their frail craft to be smashed into kindling wood against
some unseen obstruction.
The wind whistled past their ears, and deeper and blacker grew the
darkness of the canyon as their boat sped on its way.
There was no sound heard save the rush of the water against the
bank on either hand, but the speed with which they were moving was
simply appalling.
Believing that a recumbent position was safer than an upright one
—as the darkness was so intense that it seemed as though the walls
and roof of the canyon must be within easy reach of his head—Bob
threw himself backward, and, with his head resting on the tent and
his eyes directed toward the top of the canyon, awaited the issue of
events with a calmness that surprised himself.
Now and then a little patch of light, far above him, would shoot by
with such surprising swiftness that his hair would fairly stand on
end, and he would clutch the sides of the boat with a firmer grip, and
wonder how much longer this wild ride must continue, and how long
it would be before the catastrophe would come.
The slightest obstruction in their course—a bush leaning over the
water and striking the bow of their boat, and turning it from its
course by so much as a hair’s breadth—would have ended all this
suspense and anxiety in an instant of time.
But there was no bush nor anything else in their way. The channel
was as smooth and deep here as it was in the valley they had left—
how long ago? Was it an hour or a day? Bob did not know, for he
could take no note of the flight of time.
The interior of the earth must be a long way off, he thought; and
that he was drawing nearer to it every minute seemed probable, for
these little patches of light he had noticed a while back were no
longer to be seen. Above, around and beneath him was darkness.
He could not even see the water by which he and his companion
were borne along. He wasn’t certain that he had a companion in his
misery, for he had not heard anything from George since they
entered the canyon.
He was about to pronounce his name, when a blinding glare of
light shot down upon him so suddenly that it frightened him. Was he
awake or dreaming? He raised himself to a sitting posture and
looked about him.
Behind him was a black opening between the mountains, looking
exactly like the one on the other side of the range, and in front and
on each side of him was a broad and fertile valley, through which the
boat was flying with undiminished speed.
Bob rubbed his eyes and looked again; and at the same moment,
George Edwards, who had also lain down in the boat to avoid hitting
his head against the rocks, which were at least two hundred feet
above him, straightened up, revealing a face so pale and haggard that
Bob was startled. But he was not so near dead as he seemed to be, as
his actions proved.
The river, where it entered the valley, made a sudden turn to the
right, and of course the current set into the bight of the bend, taking
the boat with it, and carrying it within ten or fifteen feet of the shore,
which was thickly lined with bushes.
George’s first act was to catch up the painter and jump overboard
with it; and, although the current whirled him along as if he had been
a feather, he succeeded in crossing it and reaching the slack waters
near the bank.
The rest was comparatively easy. A turn of the painter around a
convenient sapling held the boat until the current swung it into the
eddy, and the instant it touched the shore Bob Howard sprang out.
He and George had just strength enough to make the painter fast
to the sapling, and then they sank down side by side on the grass,
and lay there panting and exhausted.
They were so dazed and bewildered by their escape from the grasp
of the current, which they regarded as little short of miraculous, that
they could not speak.
They did not move until they were brought to their feet by a low,
rumbling noise, followed by an explosion so terrific that it would
have drowned the discharge of a battery of the heaviest artillery.
“What in the name of wonder was that?” gasped Bob, who was so
weak that he shook like a leaf.
George did not answer. He was looking over Bob’s shoulder, with
eyes that seemed ready to start from their sockets.
Bob faced about, and saw a sight that well nigh extinguished the
little spark of vitality which the terrors of the canyon had left in him.
CHAPTER XXV.
SAM ASKS FOR HIS PAY.
“W e did our very best to save him, but he’s gone, and my father
is a millionaire.”
This was the burden of Arthur Howard’s thoughts, as he wandered
restlessly about the grove, with his hands in his pockets, and his eyes
fixed on the ground. The bank of the river was deserted by all save
himself.
The herdsmen were gathered in little groups about the ranch,
conversing in hushed tones, and now and then there was an ominous
growl among them that boded no good to somebody, and threatening
eyes and scowling faces were turned toward the window of the office.
The superintendent and Mr. Evans stood off by themselves,
occasionally exchanging a word or two, but generally remaining
silent and thoughtful. Uncle Bob sat alone in the office, thinking
sometimes of his lost nephew, but more frequently of the bright and
dazzling future which had so suddenly and unexpectedly opened
before him. Like Arthur, he was entirely unnoticed, the men about
him having no sympathy for him. Their thoughts were with Bob and
his companion.
“The old fellow seems to take it very much to heart,” said Mr.
Jacobs. “But it’s my opinion it is all put on for the occasion.”
“That seems to be the opinion of the herdsmen, too, if one may
judge by their looks and actions,” answered Mr. Evans. “If they had
the least excuse for it, they would put the dogs on him and his son
and drive them out of the valley.”
“I know their temper better than you do, and I am not far from
right when I say that they would serve them worse than that,” said
the superintendent. “If the men thought that Arthur and his father
were in any way mixed up with this morning’s work, a regiment of
soldiers could not save them.”
“I would give the world, if I owned it, to know whether or not they
suspect anything,” thought Arthur, who now and then stopped
behind a tree or a clump of bushes to take an anxious survey of the
groups about the ranch. “Why don’t they go off about their work, and
let me go to my room? They needn’t blame me for anything that
happened, for I didn’t suggest it, and I had no hand in carrying it out.
Sam did it out of a desire to be revenged on Bob for telling Mr.
Jacobs that he could not have employment on the ranch. But, great
Scott! what a sight that was!” said Arthur, covering his eyes with his
hands. “I don’t think I shall ever forget it.”
And he never did. The pale, despairing face which the helpless Bob
had turned toward the shore, just before his boat took its final
plunge, haunted him day and night as long as he lived.
Just then Arthur was startled by a rustling in the thicket close by
his side (he was so timid now, that every little thing frightened him),
and turned quickly, to find Sam at his side.
The latter was as serene and smiling as usual, and did not look at
all like a man who had been guilty of a crime for which his life might
at any time pay the forfeit.
Arthur was glad to see him on some accounts, and on others he
wasn’t. As he could not bear to be alone with his accusing conscience,
he wanted somebody to talk to, but he would rather it had been
somebody besides Sam.
It would have been a great relief to him if the herdsman had
saddled his horse and left the valley, never to return; but something
told him that Sam did not intend to do anything of the kind. He was
more familiar in his manner than he was the day before, and not
quite so civil.
“Well, what do you think of it?” said he, at the same time backing
up against a tree, so that he could not be seen by the men about the
ranch. “You’ve got your cousin’s fortune, and I have had my
revenge.”
“I wish you hadn’t done it,” was all Arthur could say, in reply.
“That’s a pretty way for you to talk, now, when it is too late—isn’t
it?” said Sam, in disgust. “Yesterday, you were eager for it. I saw it
very plainly, and that was the reason I proposed it.”
“But I didn’t suppose you would do it.”
“That was because you didn’t know me. I never fool about such
things. You were in dead earnest, and I knew it, and acted
accordingly.”
“Do you suppose that the men suspect anything?”
“If they did, they would make short work of us,” assured the
herdsman with a grim smile. “We wouldn’t be here to see another
sunrise, I bet you.”
Arthur winced at this, and he was greatly alarmed, too.
Sam’s use of the personal pronoun seemed to indicate that he was
not willing to shoulder all the responsibility himself. According to his
way of thinking, Arthur was as deep in the mud as he was, and Sam
did not mean to let him forget it, either.
“Everything is in our favor,” continued the herdsman. “I have
heard Bob’s father tell him more than once that he didn’t look for
anything but to see him lost in the canyon some day, and there are
others who have heard him say the same thing. So, why should they
suspect that we had anything to do with it?”
“I don’t know, I am sure. I asked the question because the men up
there,”—here Arthur nodded his head toward the ranch—“seem to be
angry about something.”
“Probably they are; for, as I told you yesterday, they don’t like you
or your father. They know that you will come into possession of this
property now, and they don’t want to have it so.”
“I don’t see how they are going to help it.”
“I don’t either; but they can make this a hot country for you, if they
set about it. Now, then, to business! I have come for my pay.”
“For your pay!” echoed Arthur.
“That’s what I said. You don’t suppose that I am going to put you
into possession of a property worth millions of dollars, and take the
risk of a lynching for nothing, do you? What kind of a hair-pin do you
think I am, anyway?”
Arthur was almost overwhelmed with amazement and terror. He
had never dreamed of this.
“I don’t owe you anything,” he managed to say at last. “I told you
that I would use my influence with my father to have you employed
on the ranch; and so I will, just as soon as Mr. Evans goes away and I
can find an opportunity to speak with him in private; but, beyond
that, I can do nothing for you.”
“It ain’t enough, pilgrim!” replied Sam, in quiet, but decided tones.
“Must have more.”
“But I say I don’t owe you anything.”
“I reckon I could make you change your mind in just two minutes,
if I should set about it,” said Sam, looking at Arthur in a way that
made him shiver all over.
“How much do you want?”
“Well, five thousand dollars will do to start on!”
“Five thousand dollars!” gasped Arthur, who thought he would
surely have fallen to the ground, if he had not placed his hand
against the nearest tree to steady himself. “Why, I haven’t got five
thousand cents to my name.”
“No, I suppose not,” replied Sam, indifferently. “Clerks, who sport
such dry goods as you had on your back when you first came here,
don’t generally have any loose change laying around. But your
father’s got it. He must have twenty or thirty thousand dollars in that
safe of his.”
“But he wouldn’t give any of it to me,” said Arthur, who was every
moment growing more astonished and alarmed.
“Oh, I guess he would, if he knew all the circumstances,” answered
the herdsman, significantly.
“But I don’t want him to know all the circumstances,” protested
Arthur, quickly. “And what excuse can I make to him for demanding
so large a sum of money?”
“That is a matter in which I am not at all interested. I don’t care
how you get it, so long as you get it; and I fancy you will make up
your mind to do it after you’ve had time to think the matter over.”
“No, I won’t,” said Arthur, his fears giving away to anger. “You had
no right to ask it of me, and I shall make no effort to get it. I
shouldn’t succeed if I did. You proposed this thing yourself, and did
the work alone and unaided, and I—”
“Well, why don’t you go on?” inquired Sam, when the other paused
and looked at him. “See here, my friend,” he added, shaking his
finger at Arthur, while his eyes flashed threateningly, “you have had
your say, and now I am going to have mine. I want that money, and I
am going to have it, too. You hear me? If you won’t get it for me, I
will go straight to your father, and tell him the whole story. I think he
would rather give me the money than lose all Bob’s millions—don’t
you?”
“Oh, don’t do that!” implored Arthur, whose anger was all gone
now. “I’ll ask him for it the first chance I get.”
“But if he wouldn’t—if he doesn’t fork out on demand, I will see
that the boys get wind of the whole affair, and what do you suppose
would be the result? They are just in the right humor for business
now, and if I should leave a little note where one of them could find
it, you and your father would be—”
Here Sam stopped, and looked up at the branches over his head. It
needed no words to explain what he meant.
“Don’t! don’t!” cried Arthur, who was trembling in every limb. “I
will ask for the money before I go to sleep to-night—honor bright, I
will.”
“I knew you would change your mind after you had thought the
matter over,” said Sam, with a meaning smile. “Now, how soon may I
expect to get the five thousand?”
“Just as soon as I can induce my father to give it to me,” promised
Arthur.
“Well, say to-morrow, then. I will meet you here in the grove right
away after breakfast. I don’t want a job at herding sheep, now, and I
don’t want to hang around any longer than I can help; so don’t waste
any time.”
“Are you going away?” asked Arthur, eagerly.
“You bet! I don’t think my constitution can stand this climate.”
“And will you promise that you’ll never come back and make any
more demands upon me?”
“Not much! I’ve struck a bonanza, and I’m going to work it as long
as the lead holds out. I know what you are thinking of, young man;
but you’ll find that I’m nobody’s fool. Now, remember, I shall be on
hand to-morrow morning, and I want to find you here with that
money.”
Sam disappeared, and Arthur resumed his wanderings about the
grove. He was frightened almost out of his senses, and wished from
the bottom of his heart that he had never seen or heard of his
companion in guilt. He even went further than that, and wished that
his uncle had given his property into the keeping of somebody else,
and that he and his father were back in Bolton, where they came
from. What in the world could he say that would induce his cousin’s
guardian to give him the five thousand dollars that Sam demanded
as hush-money? He knew very well that he couldn’t get it; and even if
he did, what good would it do him?
There was evil coming upon him; he was sure of it. And this money
would only postpone it for a little while. It would not avert it, for Sam
had said very plainly that he was not going to be satisfied with the
amount he had named—that he intended to make demands as often
as he felt like it.
Arthur grew almost wild when he recalled the man’s words. He
wrung his hands, and even quickened his steps to a run, as if he
hoped to leave his haunting fears behind him.
“There is only one thing I can do,” said he to himself, after he had
bestowed as much thought upon the situation as the perturbed state
of his mind would permit. “I must get away from here. Father must
give me money enough to take me back to Bolton. I say must do it, or
I shall help myself to what I need. There goes Mr. Evans, and father
is probably alone in the office. If he is, I will settle this matter with
him before I am an hour older.”
So saying, Arthur wiped the big drops of perspiration from his
face, put on as bold a front as he could, and started toward the ranch.
A few of the herdsmen had dispersed to their work, but those who
remained scowled at him so savagely as he passed that Arthur made
all haste to get into the hall out of their sight.
CHAPTER XXVI.
ARTHUR TRIES TO HELP HIMSELF.
A rthur found his father alone in the office, pacing the floor, with
his hands in his pockets, and a look of triumph and exultation on
his face; but, when his son entered, he sank into the nearest chair,
and tried to appear very sorrowful, indeed.
“That was a sad event, Arthur,” said he, with a long-drawn sigh—“a
very sad event. I don’t wonder that you look frightened. I was
frightened myself, and so was everybody else; but we have the
satisfaction of knowing that we used our utmost endeavors to save
him.”
We have already told how hard Uncle Bob and Arthur worked to
keep the boat from going into the canyon. The former did nothing
but shout out orders, to which nobody paid the least attention, while
Arthur stood by and looked on, without uttering a word.
“Yes, I know we did all we could,” replied Arthur, faintly; “but we
couldn’t help him. Bob knew as well as we did that he was doomed.
He told me yesterday, while we were down the river looking at the
canyon, that if I went out in a boat, I must be careful not to let that
current get hold of me. If I did, I might as well be in the rapids above
Niagara Falls, for nothing could save me. Now, father, I can’t stay
here any longer, and I want you to give me money enough to take me
back to Bolton.”
“I should like to go there myself, or somewhere else, and stay until
time has somewhat effaced the memory of this terrible occurrence;
but, under the circumstances, I don’t think it best for either one of us
to leave,” answered Uncle Bob.
“Why not?” asked Arthur. “Why can’t we both go?”
“Because our absence might give people occasion to say hard
things about us.”
“I don’t see why it should. We had nothing whatever to do with it.”
“Certainly not. But that wouldn’t make any difference to these
herdsmen, who are as unreasonable as so many pigs. I can see very
plainly that they don’t like us, and don’t want us here; but, to tell you
the plain truth, Arthur, I should be afraid to go away after what has
happened.”
“Why would you?”
“Because these ignorant men would take it as a confession of guilt
on my part.”
All unaccustomed as Arthur was to reasoning a posteriori—that is,
from the effect to the cause—he told himself that his father never
could have reached this conclusion if he had not felt guilty.
Although Uncle Bob tried to believe that he was sorry his nephew
was gone, he did not succeed in deceiving either himself or those
about him; and it was not at all improbable that an attempt at flight
on his part would have resulted in something serious.
Whenever Uncle Bob allowed his mind to dwell upon this matter,
he became as badly frightened as Arthur was. Dearly as he loved
money, he loved life better, and he would willingly have surrendered
his nephew’s millions if, by so doing he could have transported
himself and Arthur back to Bolton, where he knew they would be
safe.
“And must we stay here in the midst of these lawless men, who
may at any moment take a notion to hang us?” exclaimed Arthur in
great alarm.
“It seems to be our only chance,” confessed Uncle Bob, in agitated
tones. “I have thought the matter all over, and I don’t see that we can
do anything else. If we could only make these men believe that we
take the matter as much to heart as they do, they wouldn’t think so
hard of us; but they are very obstinate and set in their ways, and it
will take time to accomplish that.”
“But, father, I can’t stay here,” insisted Arthur, jumping to his feet,
and walking nervously up and down the floor. “I shall go crazy if I do
—I know I shall. If you won’t go with me, give me money and let me
go alone. You’ve got plenty of it. I heard one of the men say that there
were twenty or thirty thousand dollars in that safe.”
“There’s more than that in there,” said Uncle Bob. “But it isn’t the
money I care for. I was thinking of you. It would not be best for you
to leave now.”
“I will take all the risk,” pleaded Arthur. “Don’t refuse, for if you
do, there is no telling what may happen.”
“Don’t get excited over it,” advised Uncle Bob, who was anything
but calm himself. “Be governed by me, and hope for the best.”
Arthur who became almost frantic whenever he thought of Sam,
and the interview he had appointed for the morrow, “right away after
breakfast,” said everything he could think of to induce his father to
grant his request, but he urged and begged in vain.
When Uncle Bob once made up his mind to a thing, he was fully as
obstinate and unreasonable as the herdsmen to whom he had
referred in tones so contemptuous, and Arthur might as well have
argued with the stone walls of the ranch.
Finding that he could make no impression upon his father, the boy
grew angry, and was more than once on the point of declaring that
Sam had made a demand upon him for five thousand dollars,
threatening, in case of refusal, to publish a story of his own getting
up, that would induce the herdsmen to make short work of both of
them.
But his guilty fears would not allow him to do it, and, besides, he
had some other plans in his head that he wanted to try first, so he
bolted out of the office, banging the door behind him.
“He’s the meanest old hulks of a father that any fellow ever had,”
thought Arthur, stopping in the hall long enough to shake his fist at
the door, “and I don’t care what happens to him. As he is too pig-
headed to do as I want him to do, I’ll help myself to every cent there
is in that safe this very night if I can get in. If I succeed, I will give
Sam his hush-money to-morrow morning, and hire him to show me
the way to the railroad station. I have seen quite enough of Arizona,
and if I can only get aboard a train of cars that is headed for the East,
the prospect of owning four times four million dollars won’t bring me
back here.”
While Arthur was talking to himself in this way, he looked
cautiously out of the door, and, having satisfied himself, by a few
minutes’ reconnaissance, that the herdsmen had all dispersed, he
walked across the porch, and bent his steps toward the grove.
He wanted to be alone, and this was the most retired spot he could
find. It was utterly impossible for him to keep still, and here he could
walk about among the trees without being seen by anybody.
Arthur had been in the grove, perhaps half an hour, keeping his
thoughts busy with the plans he intended to put into operation in
case his attempt to steal the money in the safe did not prove
successful, when he saw the superintendent stop in front of the porch
with a couple of horses that were saddled and bridled.
After he had stood there for a minute or two, Uncle Bob came out
of the ranch, with his hat on his head and a riding-whip in his hand.
He mounted one of the horses, Mr. Jacobs sprang upon the other,
and together they rode away.
“They are going off somewhere on business,” soliloquized Arthur,
“and this is as good an opportunity as I shall have to take a look at
that safe. I wish the money in it belonged to me, and that the old
man wanted some of it. He shouldn’t have a cent if he was starving.”
Arthur gave the horsemen time to get out of sight, and then he left
the grove and walked toward the ranch.
He went into the office, and having locked the door to prevent
interruption, he began an examination of the safe, which was set into
the wall so that nothing but the face of it could be seen.
If it had been provided with a combination lock, Arthur would
have set to work upon it at once; but as it was an old-fashioned
article, requiring a key to open it, he could do nothing.
Thinking it possible that his father might have left the key in the
room, he began looking for it in the bookcases, under the lounge,
along the edge of the carpet—in every place, in fact, that seemed to
offer the least chance for concealment, but his search was in vain.
“It is in his pocket, most likely,” said Arthur, as he unlocked the
door, sat down in one of the easy chairs, and opened a book, which
he had taken at random down from one of the shelves. “I’ll just hang
around the rest of the day, and satisfy myself on that point. That key
is the only thing that stands in my way. If I can get my hands on that,
the rest will be easy enough, for I know how to open the safe.”
Arthur turned his chair about so that he could not see the river
when he happened to glance out of the window—somehow, he could
not bear the sight of it now—and tried to amuse himself by looking at
the engravings in the book he held in his hand; but the excitement
and suspense which had taken the place of his fears were too much
for him, and sometimes he would spring to his feet and rush about
the room like some caged wild animal.
But he was quiet enough when his father returned about dinner-
time, and came into the office, accompanied by the superintendent.
Some argument had arisen between them regarding the business
of the ranch, and, in order to settle it, they had to refer to the books
that were in the safe.
Arthur saw his father take the key from his pocket and insert it in
the lock, and took particular notice to the way he twirled the knob.
When the door swung open and the interior of the safe was
disclosed to his view, Arthur was not a little astonished.
One of the shelves was piled full of greenbacks, and on the shelf
under it were four large tin boxes, which were filled to the brim with
bright, shining gold pieces.
As he did not care to stay there and listen to a discussion about
matters of which he knew nothing and cared less, Arthur put away
his book and went out into the hall.
He walked about for a few minutes, with his eyes fastened
thoughtfully on the floor, and then hurried to his room and began to
unpack his valise. He had not thought of it before.
“There’s a lot of money in that safe,” said he to himself, “and I
must have something to carry it in, for I couldn’t get the tenth part of
it into my pockets. I don’t know what the old man will say when he
finds that his safe has been emptied; and, in order to keep it from his
knowledge as long as I can, I will take the key with me when I go. I
wish now that I had told Sam to meet me about midnight. If he
comes to the grove this afternoon, I will make new arrangements
with him.”
Arthur spent the entire afternoon in the grove, with his thoughts
for company; but Sam did not put in an appearance. He knew better.
He had made some threats against Bob in the presence of some of
the herdsmen, and the valley was not a safe place for him. He was
idling away the time in the seclusion of a deep ravine a short distance
away, waiting impatiently for the morrow.
Arthur went to bed as soon as he had eaten his supper, and when
his father came into the room, about eleven o’clock, he lay with his
face to the wall, apparently fast asleep. The two had but little to say
to each other since the interview in the morning.
Uncle Bob tried to be sociable while they were at the table, but
Arthur would scarcely listen to him.
“I was the only friend he had on the ranch,” the youth kept saying
to himself, “and I want him to see that he has made an enemy of me.
If he doesn’t know it now he will find it out very shortly.”
It was long after midnight before Arthur made any move to show
that he was awake. Then he turned over very cautiously, and, after
listening intently for a few minutes, he made up his mind that the
time for action had arrived.
Noiselessly he arose from the bed and moved towards the chair
upon which his father had deposited his clothing.
After a little fumbling in the dark, he found the pocket of which he
was in search, and his fingers closed tightly on the coveted key.
Hardly able to repress an exclamation of triumph, Arthur picked
up his valise, which he had placed at the foot of his bed, unlocked the
door and passed through the hall into the office.
Feeling his way to the safe, he put the key into the lock, turned the
knob, and the door opened for him.
“It’s all mine,” thought he, as he opened his valise and proceeded
to stow the greenbacks away in it. “If father wants to stay here, and
run the risk of being hanged, he can do it and welcome; but I’m off
for Bolton, this very—”
All on a sudden, the door of the office creaked on its hinges, and
the room was brilliantly illuminated. With a piercing cry of terror,
Arthur looked over his shoulder and saw his father standing behind
him, holding a lamp in one hand and a big revolver in the other.
CHAPTER XXVII.
THE LISTENER IN THE GROVE.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookfinal.com