[FEATURE] toclipboard & fromclipboard
This commit is contained in:
21
ascii.cpp
21
ascii.cpp
@@ -431,7 +431,7 @@ int rnd(int x) {
|
|||||||
srand(x);
|
srand(x);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
char str_tmp[256];
|
char str_tmp[1024];
|
||||||
const char* tostr(float val) {
|
const char* tostr(float val) {
|
||||||
return SDL_itoa(val, str_tmp, 10);
|
return SDL_itoa(val, str_tmp, 10);
|
||||||
}
|
}
|
||||||
@@ -571,3 +571,22 @@ void filein(const char* str, uint16_t addr, uint16_t size) {
|
|||||||
fread(&mem[addr], size, 1, f);
|
fread(&mem[addr], size, 1, f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void toclipboard(const char* str) {
|
||||||
|
SDL_SetClipboardText(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* fromclipboard() {
|
||||||
|
char* text = SDL_GetClipboardText();
|
||||||
|
int len = strlen(text);
|
||||||
|
if (len > 1023) {
|
||||||
|
len = 27;
|
||||||
|
SDL_memcpy(str_tmp, "ERROR! CLIPBOARD TOO LARGE", len);
|
||||||
|
} else {
|
||||||
|
SDL_memcpy(str_tmp, text, len);
|
||||||
|
}
|
||||||
|
str_tmp[len] = '\0';
|
||||||
|
SDL_free((void*)text);
|
||||||
|
|
||||||
|
return str_tmp;
|
||||||
|
}
|
||||||
3
ascii.h
3
ascii.h
@@ -180,3 +180,6 @@ void load(const char* str);
|
|||||||
|
|
||||||
void fileout(const char* str, uint16_t addr, uint16_t size);
|
void fileout(const char* str, uint16_t addr, uint16_t size);
|
||||||
void filein(const char* str, uint16_t addr, uint16_t size);
|
void filein(const char* str, uint16_t addr, uint16_t size);
|
||||||
|
|
||||||
|
void toclipboard(const char* str);
|
||||||
|
const char* fromclipboard();
|
||||||
13
lua.cpp
13
lua.cpp
@@ -381,6 +381,17 @@ extern "C" {
|
|||||||
filein(str, addr, size);
|
filein(str, addr, size);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int cpp_toclipboard(lua_State *L) {
|
||||||
|
const char* str = luaL_checkstring(L, 1);
|
||||||
|
toclipboard(str);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int cpp_fromclipboard(lua_State *L) {
|
||||||
|
lua_pushstring(L, fromclipboard());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define STATE_STOPPED 0
|
#define STATE_STOPPED 0
|
||||||
@@ -473,6 +484,8 @@ void lua_init(const char* filename, const bool start_playing) {
|
|||||||
|
|
||||||
lua_pushcfunction(L,cpp_fileout); lua_setglobal(L, "fileout");
|
lua_pushcfunction(L,cpp_fileout); lua_setglobal(L, "fileout");
|
||||||
lua_pushcfunction(L,cpp_filein); lua_setglobal(L, "filein");
|
lua_pushcfunction(L,cpp_filein); lua_setglobal(L, "filein");
|
||||||
|
lua_pushcfunction(L,cpp_toclipboard); lua_setglobal(L, "toclipboard");
|
||||||
|
lua_pushcfunction(L,cpp_fromclipboard); lua_setglobal(L, "fromclipboard");
|
||||||
|
|
||||||
lua_pushinteger(L, 0); lua_setglobal(L, "KEY_UNKNOWN");
|
lua_pushinteger(L, 0); lua_setglobal(L, "KEY_UNKNOWN");
|
||||||
lua_pushinteger(L, 4); lua_setglobal(L, "KEY_A");
|
lua_pushinteger(L, 4); lua_setglobal(L, "KEY_A");
|
||||||
|
|||||||
Reference in New Issue
Block a user