Create function pointer to lua function adapter and migrate what we can
[lsnes.git] / lua-int.hpp
blobac200c421f03113c6ac85ad5944ebedfd21b36a8
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 char buffer[1024];
21 sprintf(buffer, "argument #%i to %s must be numeric", argindex, fname);
22 lua_pushstring(LS, buffer);
23 lua_error(LS);
25 return static_cast<T>(lua_tonumber(LS, argindex));
28 template<typename T>
29 void get_numeric_argument(lua_State* LS, unsigned argindex, T& value, const char* fname)
31 if(lua_isnoneornil(LS, argindex))
32 return;
33 if(lua_isnone(LS, argindex) || !lua_isnumber(LS, argindex)) {
34 char buffer[1024];
35 sprintf(buffer, "argument #%i to %s must be numeric if present", argindex, fname);
36 lua_pushstring(LS, buffer);
37 lua_error(LS);
39 value = static_cast<T>(lua_tonumber(LS, argindex));
42 #endif