added two lua tutorials

git-svn-id: svn://anubis/misc/lua@130 bd8a9e45-a331-0410-811e-c64571078777
This commit is contained in:
josh committed 2009-09-12 15:17:53 +00:00
1 parent 78032af165
commit e74bc7d391
6 files changed
+134

No files matched your search

+9
View File
@@ -0,0 +1,9 @@
TARGET := tut
CPPFLAGS := -I/usr/include/lua5.1
LDFLAGS := -llua5.1
all: $(TARGET)
$(TARGET): $(TARGET).cc
$(CXX) -o $@ $(CPPFLAGS) $(CXXFLAGS) $^ $(LDFLAGS)
+3
View File
@@ -0,0 +1,3 @@
-- The first program in every language
io.write("Hello world, from", _VERSION, "!\n")
+48
View File
@@ -0,0 +1,48 @@
#include <iostream>
#include <lua.hpp>
using namespace std;
void report_errors(lua_State * L, int status)
{
if ( status != 0 )
{
cerr << "-- " << lua_tostring(L, -1) << endl;
lua_pop(L, 1); // remove error message
}
}
int main(int argc, char ** argv)
{
for ( int n = 1; n < argc; ++n )
{
const char * file = argv[n];
lua_State * L = lua_open();
luaL_openlibs(L);
#if 0
luaopen_io(L); // provides io.*
luaopen_base(L);
luaopen_table(L);
luaopen_string(L);
luaopen_math(L);
#endif
cerr << "-- Loading file: " << file << endl;
int s = luaL_loadfile(L, file);
if ( s == 0 )
{
// execute Lua program
s = lua_pcall(L, 0, LUA_MULTRET, 0);
}
report_errors(L, s);
lua_close(L);
cerr << endl;
}
return 0;
}