Pack movie data in memory
[lsnes.git] / include / core / lua-int.hpp
blob68957db34dec3ee8ff02b5f3261f74fc433defc8
1 #ifndef _lua_int__hpp__included__
2 #define _lua_int__hpp__included__
4 #include "lua.hpp"
5 #include <cstdio>
6 #include <cstdlib>
7 extern "C"
9 #include <lua.h>
12 std::string get_string_argument(lua_State* LS, unsigned argindex, const char* fname);
13 bool get_boolean_argument(lua_State* LS, unsigned argindex, const char* fname);
14 extern lua_render_context* lua_render_ctx;
15 extern controller_frame* lua_input_controllerdata;
18 template<typename T>
19 T get_numeric_argument(lua_State* LS, unsigned argindex, const char* fname)
21 if(lua_isnone(LS, argindex) || !lua_isnumber(LS, argindex)) {
22 char buffer[1024];
23 sprintf(buffer, "argument #%i to %s must be numeric", argindex, fname);
24 lua_pushstring(LS, buffer);
25 lua_error(LS);
27 return static_cast<T>(lua_tonumber(LS, argindex));
30 template<typename T>
31 void get_numeric_argument(lua_State* LS, unsigned argindex, T& value, const char* fname)
33 if(lua_isnoneornil(LS, argindex))
34 return;
35 if(lua_isnone(LS, argindex) || !lua_isnumber(LS, argindex)) {
36 char buffer[1024];
37 sprintf(buffer, "argument #%i to %s must be numeric if present", argindex, fname);
38 lua_pushstring(LS, buffer);
39 lua_error(LS);
41 value = static_cast<T>(lua_tonumber(LS, argindex));
44 #endif