2 #include "mainloop.hpp"
6 class lua_hostmemory_read
: public lua_function
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);
18 lua_pushnumber(LS
, static_cast<uint8_t>(h
[address
]));
23 class lua_hostmemory_write
: public lua_function
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);