monotone

monotone Mtn Source Tree

Root/lua.hh

1#ifndef __LUA_HH__
2#define __LUA_HH__
3
4#include <set>
5#include <string>
6
7struct lua_State;
8
9// This Lua object represents a single imperative transaction with the lua
10// interpreter. if it fails at any point, all further commands in the
11// transaction are ignored. it cleans the lua stack up when it is
12// destructed, so no need to pop values when you're done.
13
14struct
15Lua
16{
17 lua_State * st;
18 bool failed;
19 static std::set<std::string> missing_functions;
20
21 Lua(lua_State * s);
22 ~Lua();
23
24 void fail(std::string const & reason);
25 bool ok();
26 void report_error();
27
28 // getters
29 Lua & get(int idx = LUA_GLOBALSINDEX);
30 Lua & get_fn(int idx = LUA_GLOBALSINDEX);
31 Lua & get_tab(int idx = LUA_GLOBALSINDEX);
32 Lua & get_str(int idx = LUA_GLOBALSINDEX);
33 Lua & get_num(int idx = LUA_GLOBALSINDEX);
34 Lua & get_bool(int idx = LUA_GLOBALSINDEX);
35
36 // extractors
37 Lua & extract_str_nolog(std::string & str);
38 Lua & extract_str(std::string & str);
39 Lua & extract_classified_str(std::string & str);
40 Lua & extract_int(int & i);
41 Lua & extract_double(double & i);
42 Lua & extract_bool(bool & i);
43
44 // table iteration
45 Lua & begin();
46 bool next();
47
48 // pushers
49 Lua & push_str(std::string const & str);
50 Lua & push_int(int num);
51 Lua & push_int(double num);
52 Lua & push_bool(bool b);
53 Lua & push_nil();
54 Lua & push_table();
55 Lua & set_table(int idx = -3);
56 Lua & call(int in, int out);
57 Lua & pop(int count = 1);
58 Lua & func(std::string const & fname);
59 Lua & loadstring(std::string const & str, std::string const & identity);
60 Lua & loadfile(std::string const & filename);
61};
62
63bool run_string(lua_State * st,
64 std::string const &str,
65 std::string const & identity);
66bool run_file(lua_State * st, std::string const &filename);
67void add_functions(lua_State * st);
68
69// Local Variables:
70// mode: C++
71// fill-column: 76
72// c-file-style: "gnu"
73// indent-tabs-mode: nil
74// End:
75// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
76
77#endif

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status