Add lua functions to manipulate emulator settings
[lsnes.git] / lua-int.hpp
blobafb27ed56ee40b0ab7ffc07129014b45daaed8f3
1 #ifndef _lua_int__hpp__included__
2 #define _lua_int__hpp__included__
4 #include "lua.hpp"
5 extern "C"
7 #include <lua.h>
10 std::string get_string_argument(lua_State* LS, unsigned argindex, const char* fname);
11 bool get_boolean_argument(lua_State* LS, unsigned argindex, const char* fname);
12 extern lua_render_context* lua_render_ctx;
13 extern controls_t* lua_input_controllerdata;
16 template<typename T>
17 T get_numeric_argument(lua_State* LS, unsigned argindex, const char* fname)
19 if(lua_isnone(LS, argindex) || !lua_isnumber(LS, argindex)) {
20 lua_pushfstring(LS, "argument #%i to %s must be numeric", argindex, fname);
21 lua_error(LS);
23 return static_cast<T>(lua_tonumber(LS, argindex));
26 template<typename T>
27 void get_numeric_argument(lua_State* LS, unsigned argindex, T& value, const char* fname)
29 if(lua_isnoneornil(LS, argindex))
30 return;
31 if(lua_isnone(LS, argindex) || !lua_isnumber(LS, argindex)) {
32 lua_pushfstring(LS, "argument #%i to %s must be numeric if present", argindex, fname);
33 lua_error(LS);
35 value = static_cast<T>(lua_tonumber(LS, argindex));
38 #endif