LuCa: A Language for embedding Lua in C

Bibliographic Information

Other Title
  • CにLuaを容易に埋め込むための言語LuCa

Search this article

Description

既存の多くのスクリプト言語は,Cプログラムとの連携を意図したAPIを提供している.特にスクリプト言語Luaは,CプログラムにLuaインタプリタが組み込まれることを前提にして設計されており,Cで実装された多くの既存のソフトウェアもLuaを組み込んでいる.しかし,CプログラムとLuaを連携する際,プログラマはCとLuaの間のデータのやりとりに煩雑なC APIを利用しなければならない.このことは,プログラマにとって実装コストの増加の原因となり,さらに,C APIの規約に従う必要がある結果,ソースコードの見通しも悪くなる.この問題を解決するため,我々はC言語を拡張し,LuaコードをCコード中に直接埋め込んで記述することのできる言語LuCaを提案し,その処理系を実装する.LuCaでは,埋め込まれたLuaコードからCコードの変数や関数にアクセスすることができる.そのため,C APIを陽に使うことなくLuaコードらしい自然な記述を行うことが可能になり,プログラマの負担を軽減することができる.LuCa処理系は与えられたLuCaコードをCコードへと変換する.Luaとの連携部分はC APIを適切に利用したコードとするため,LuCa処理系は特殊なCコンパイラや特殊なLua処理系を用意する必要はない.本発表では,LuCa言語の設計とその処理系の実装について述べる.

Most scripting languages provide C APIs that make these languages cooperate with programs written C. Especially, scripting language Lua is designed on the assumption that its interpreter is embedded in a C program. In fact, a lot of existing software written in C embed Lua interpreter. However, when embedding a Lua program in a C program, it is necessary for the programmer to use complicated C APIs provided by Lua for trasferring data between C and Lua. This increases the developing cost of programs within which C and Lua cooperate. Worse, obeying protocols of Lua's C APIs spoils the readability of source programs. To resolve this problem, we propose a new language LuCa that extends C to make it possible to embed Lua code directly, and implement a LuCa processor. In a LuCa program, embedded Lua code can access variables and fucntions in C. Thus, using LuCa enables the programmer to write Lua-like code without explicit C APIs and reduces the programmer's burden. LuCa processor converts a given LuCa code into a C code. Since cooperating part of C and Lua is converted into C code with existing C APIs, the LuCa processor does not require special C compiler and Lua interpreter. We describe LuCa language and the implementation of its processor.

Journal

Keywords

Details 詳細情報について

Report a problem

Back to top