background preloader

Lua

Facebook Twitter

Socket

Probablycorey's wax at master - GitHub. Reference. [ANN] LuaJIT-2.0.0-beta1. [ANN] nixio 0.2 - General Purpose, POSIX and I/O library. Re: Game scripting [was: Re: evolutionary programming & Lua] An extensible extension language. Lua - an extensible extension language by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes Filho Abstract. This paper describes Lua, a language for extending applications. Lua combines procedural features with powerful data description facilities, by using a simple, yet powerful, mechanism of tables. Introduction There is increasing demand for customizable applications. Configuration languages come in several flavors, ranging from simple languages for selecting preferences, usually implemented as parameter lists in command lines or as variable-value pairs read from configuration files (e.g., MS-Windows' .ini files, X11 resource files), to embedded languages, for extending applications with user defined functions based on primitives provided by the applications.

What makes extension languages different from stand alone languages is that they only work embedded in a host client, called the host program. Lua satisfies the requirements listed above quite well. Fallbacks "gc" Lean & Mean Tokyo Cabinet Recipes (with Lua) - FutureRuby &# Igrigorik's tokyo-recipes at master - GitHub. LuaSQL: Database connectivity for the Lua programming language. Introduction LuaSQL is a simple interface from Lua to a number of database management systems. It includes a set of drivers to some popular databases (currently PostgreSQL, ODBC, MySQL, SQLite, Oracle, and ADO; Interbase and Sybase are in our plans).

LuaSQL defines a simple object-oriented API. All drivers should implement this common API, but each one is free to offer extensions. LuaSQL defines one single global variable, a table called luasql. This table is used to store the initialization methods of the loaded drivers. LuaSQL is free software and uses the same license as Lua 5.1. Compiling LuaSQL is distributed as a set of C source files: a pair of common source and header files (luasql.h and luasql.c); and one source file for each driver.

Installation All LuaSQL drivers follow the package model for Lua 5.1 and therefore should be "installed" in your package.path. Windows users can use the compiled versions of LuaSQL available at LuaForge Error handling Drivers require "luasql.odbc" Methods. Programming in Lua : contents. LuaSocket: Project Info. Iterating bits in Lua. Today's question on #lua was (roughly speaking): How do you make a truth table in Lua? OK, Lua has no bit operators, and it may not be the best language for intensive bit manipulation.

Still, you can go a long way with the % operator: function bit(p) return 2 ^ (p - 1) -- 1-based indexing end -- Typical call: if hasbit(x, bit(3)) then ... function hasbit(x, p) return x % (p + p) >= p end function setbit(x, p) return hasbit(x, p) and x or x + p end function clearbit(x, p) return hasbit(x, p) and x - p or x end As a digression, we could trivially use hasbit to iterate over a number and implement bitwise functions: function bitor(x, y) local p = 1; local z = 0; local limit = x > y and x or y while p <= limit do if hasbit(x, p) or hasbit(y, p) then z = z + p end p = p + p end return z end We can improve on that by working across the numbers from the high-order end: Now, let's consider what a truth table function might look like. And this does work as expected: LuaSocket: Introduction to the core. LuaSocket is a Lua extension library that is composed by two parts: a C core that provides support for the TCP and UDP transport layers, and a set of Lua modules that add support for the SMTP (sending e-mails), HTTP (WWW access) and FTP (uploading and downloading files) protocols and other functionality commonly needed by applications that deal with the Internet.

This introduction is about the C core. Communication in LuaSocket is performed via I/O objects. These can represent different network domains. Currently, support is provided for TCP and UDP, but nothing prevents other developers from implementing SSL, Local Domain, Pipes, File Descriptors etc. The API design had two goals in mind. One of the simplifications is the receive pattern capability. Another advantage is the flexible timeout control mechanism. Finally, the host name resolution is transparent, meaning that most functions and methods accept both IP addresses and host names. Example: A simple echo server, using LuaSocket. LuaSocket: HTTP support. HTTP (Hyper Text Transfer Protocol) is the protocol used to exchange information between web-browsers and servers. The http namespace offers full support for the client side of the HTTP protocol (i.e., the facilities that would be used by a web-browser implementation). The implementation conforms to the HTTP/1.1 standard, RFC 2616.

The module exports functions that provide HTTP functionality in different levels of abstraction. From the simple string oriented requests, through generic LTN12 based, down to even lower-level if you bother to look through the source code. To obtain the http namespace, run: -- loads the HTTP module and any libraries it requires local http = require("socket.http") URLs must conform to RFC 1738, that is, an URL is a string in the form: [ MIME headers are represented as a Lua table in the form: Field names are case insensitive (as specified by the standard) and all functions work with lowercase field names. Wiki: Split Join. "split" [1] and "join" [2] are two common string operators that are essentially inverse operations of each other. Split separates a string containing a delimiter into the list of substrings between that delimiter. Join combines a list of strings into a new string by inserting a delimiter between each string. There are various ways to design and implement these functions in Lua, as described below.

Joining list of strings With Lua 5.x you can use table.concat[3] for joining: table.concat(tbl, delimiter_str). table.concat({"a", "b", "c"}, ",") Other interfaces are possible, largely dependent on the choice of split interface since join is often intended to be the inverse operation of split. Splitting Strings First of all, although Lua does not have a split function is its standard library, it does have string.gmatch[4], which can be used instead of a split function in many cases. Local example = "an example string"for i in string.gmatch(example, "%S+") do print(i) end split("a,b,c", ",", 2) Fix: Mixi Engineers’ Blog » Lua on Tyrant: DBサーバにLLを組み込む. 遅めの夏休みで那須塩原に行ってきたmikioです。 牧場でアルパカに触ってきたのですが、めちゃかわいかったです。

さて今回は、Tokyo Tyrant(TT)にスクリプト言語Luaの処理系を組み込んで使う方法について解説します。 つか、Luaって何? Lua(公式サイトによると「るーあ(LOO-ah)」と発音)という言語の名前は聞いたことがあっても、数あるマイナー言語のひとつと思って特に気にかけていない人も多いと思います。 私もそうでした。 しかし、今では、C言語使いの第2言語・第3言語として使うにはとても有望な言語だと思っています。 Luaに関する日本語の情報はまだ多くはないのですが、以下のサイトを順に読むとだいたいの雰囲気が掴めると思います。 Luaは言語仕様が小さいので、とても習得しやすいです。 Luaによるプログラミングでは、Perlでいうところのハッシュや配列としての機能を兼ね備える「テーブル」という機構を使いこなすのが要点となります。 私が新しい言語を覚える時によくやるのが、DBM風のインターフェイスを実装することです。 コンストラクタ(new)のあたりが少しわかりにくいかもしれませんが、function myfunc(arg){ ... } という書き方は myfunc = function(arg){ ... } と書くのと同義であるという仕様を考えると理解できます。 後半の、オブジェクトを利用するところも面白いですね。 Luaを組み込む DBMがよく「組み込み用データベース」などと称されるように、Luaもよく「組み込み用スクリプト言語」などと称されます。 余談ですが、TTに最初に組み込もうとしたのはRubyの処理系でした。 一方で、Luaの処理系はネイティブスレッドと併用して使うことができます。 上記で処理系のインスタンスと言っているものは、CのAPIでは lua_State という構造体で表現されます。 激烈に簡単ですよね! さて、チャンクというのは、実行される文の塊のことで、関数と同じように扱うことができます。

激烈に簡単ですよね! Tokyo TyrantとLua さて、いよいよ本題です。 実際に使ってみましょう。 . 次に、Luaスクリプトを作ります。 Function echo(key, value) return key .. ":" .. value end $ . 足あとデータベース. Wiki: Home Page. Embeddable scripting with Lua. While interpreted programming languages such as Perl, Python, PHP, and Ruby are increasingly favored for Web applications -- and have long been preferred for automating system administration tasks -- compiled programming languages such as C and C++ are still necessary.

The performance of compiled programming languages remains unmatched (exceeded only by the performance of hand-tuned assembly), and certain software -- including operating systems and device drivers -- can only be implemented efficiently using compiled code. Indeed, whenever software and hardware need to mesh seamlessly, programmers instinctively reach for a C compiler: C is primitive enough to get "close to the bare metal" -- that is, to capture the idiosyncrasies of a piece of hardware -- yet expressive enough to offer some high-level programming constructs, such as structures, loops, named variables, and scope. However, scripting languages have distinct advantages, too. Lua novelties Lua types. Back to top $ (echo '#! 5.1 Reference Manual - contents. The reference manual is the official definition of the Lua language. For a complete introduction to Lua programming, see the book Programming in Lua. This manual is also available as a book: Lua 5.1 Reference Manual by R.

Ierusalimschy, L. H. de Figueiredo, W. Celes Lua.org, August 2006 ISBN 85-903798-3-3 Buy a copy of this book and help to support the Lua project. Copyright © 2006–2012 Lua.org, PUC-Rio. Contents Index. Lua 5.1 Reference Manual. By Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes Copyright © 2006–2012 Lua.org, PUC-Rio.

Freely available under the terms of the Lua license. contents · index · other versions · english · português · español Lua is an extension programming language designed to support general procedural programming with data description facilities. It also offers good support for object-oriented programming, functional programming, and data-driven programming. Lua is intended to be used as a powerful, light-weight scripting language for any program that needs one. Lua is implemented as a library, written in clean C (that is, in the common subset of ANSI C and C++). Being an extension language, Lua has no notion of a "main" program: it only works embedded in a host client, called the embedding program or simply the host.

Lua is free software, and is provided as usual with no guarantees, as stated in its license. Like any other reference manual, this document is dry in places. The form.