Lua: Fix type confusion between signed and unsigned
[lsnes.git] / include / library / lua-function.hpp
blob0300360f0686e43fd99b3157f9c0596c3040c55a
1 #ifndef _library__lua_function__hpp__included__
2 #define _library__lua_function__hpp__included__
4 namespace lua
6 class parameters;
7 class state;
9 /**
10 * Group of functions.
12 class function_group
14 public:
15 /**
16 * Create a group.
18 function_group();
19 /**
20 * Destroy a group.
22 ~function_group();
23 /**
24 * Add a function to group.
26 void do_register(const std::string& name, function& fun);
27 /**
28 * Drop a function from group.
30 void do_unregister(const std::string& name, function& dummy);
31 /**
32 * Request callbacks on all currently registered functions.
34 void request_callback(std::function<void(std::string, function*)> cb);
35 /**
36 * Bind a callback.
38 * Callbacks for all registered functions are immediately called.
40 int add_callback(std::function<void(std::string, function*)> cb,
41 std::function<void(function_group*)> dcb);
42 /**
43 * Unbind a calback.
45 void drop_callback(int handle);
46 private:
47 char dummy;
50 /**
51 * Function implemented in C++ exported to Lua.
53 class function
55 public:
56 /**
57 * Register function.
59 function(function_group& group, const std::string& name) throw(std::bad_alloc);
60 /**
61 * Unregister function.
63 virtual ~function() throw();
65 /**
66 * Invoke function.
68 virtual int invoke(state& L) = 0;
69 protected:
70 std::string fname;
71 function_group& group;
74 /**
75 * Register multiple functions at once.
77 class functions
79 public:
80 /**
81 * Entry in list.
83 struct entry
85 const std::string& name;
86 std::function<int(state& L, parameters& P)> func;
88 /**
89 * Create new functions.
91 * Parameter grp: The group to put the functions to.
92 * Parameter basetable: The base table to interpret function names relative to.
93 * Parameter fnlist: The list of functions to register.
95 functions(function_group& grp, const std::string& basetable, std::initializer_list<entry> fnlist);
96 /**
97 * Dtor.
99 ~functions();
100 private:
101 class fn : public function
103 public:
104 fn(function_group& grp, const std::string& name, std::function<int(state& L, parameters& P)> _func);
105 ~fn() throw();
106 int invoke(state& L);
107 private:
108 std::function<int(state& L, parameters& P)> func;
110 functions(const functions&);
111 functions& operator=(const functions&);
112 std::set<fn*> funcs;
117 #endif