Factor stuff related to our_movie into separate file
[lsnes.git] / lua / hostmemory.cpp
blob5e03fa346bf6c84ee9ba0f3084242258234a5fcd
1 #include "lua-int.hpp"
2 #include "mainloop.hpp"
4 namespace
6 class lua_hostmemory_read : public lua_function
8 public:
9 lua_hostmemory_read() : lua_function("hostmemory.read") {}
10 int invoke(lua_State* LS, window* win)
12 size_t address = get_numeric_argument<size_t>(LS, 1, fname.c_str());
13 auto& h = get_host_memory();
14 if(address >= h.size()) {
15 lua_pushboolean(LS, 0);
16 return 1;
18 lua_pushnumber(LS, static_cast<uint8_t>(h[address]));
19 return 1;
21 } hostmemory_read;
23 class lua_hostmemory_write : public lua_function
25 public:
26 lua_hostmemory_write() : lua_function("hostmemory.write") {}
27 int invoke(lua_State* LS, window* win)
29 size_t address = get_numeric_argument<size_t>(LS, 1, fname.c_str());
30 uint8_t value = get_numeric_argument<uint8_t>(LS, 2, fname.c_str());
31 auto& h = get_host_memory();
32 if(address >= h.size())
33 h.resize(address + 1);
34 h[address] = value;
35 return 0;
37 } hostmemory_write;