[FEAT] substr
This commit is contained in:
10
ascii.cpp
10
ascii.cpp
@@ -423,9 +423,9 @@ int rnd(int x) {
|
||||
srand(x);
|
||||
}*/
|
||||
|
||||
char tostr_tmp[256];
|
||||
char str_tmp[256];
|
||||
const char* tostr(float val) {
|
||||
return SDL_itoa(val, tostr_tmp, 10);
|
||||
return SDL_itoa(val, str_tmp, 10);
|
||||
}
|
||||
|
||||
void debug_set_prompt() {
|
||||
@@ -489,6 +489,12 @@ const char* chr(uint8_t ascii) {
|
||||
return chr_trans;
|
||||
}
|
||||
|
||||
const char* substr(const char* str, uint8_t start, uint8_t length) {
|
||||
memcpy(str_tmp, &str[start], length);
|
||||
str_tmp[length] = '\0';
|
||||
return str_tmp;
|
||||
}
|
||||
|
||||
void setchar(uint8_t index, uint8_t b0, uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, uint8_t b5, uint8_t b6, uint8_t b7) {
|
||||
mem[MEM_CHAR_OFFSET+index*8] = b0;
|
||||
mem[MEM_CHAR_OFFSET+index*8+1] = b1;
|
||||
|
||||
1
ascii.h
1
ascii.h
@@ -163,6 +163,7 @@ void debug_get_cmd();
|
||||
|
||||
uint8_t ascii(const char *str, uint8_t index);
|
||||
const char* chr(uint8_t ascii);
|
||||
const char* substr(const char* str, uint8_t start, uint8_t length);
|
||||
|
||||
void setchar(uint8_t index, uint8_t b0, uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, uint8_t b5, uint8_t b6, uint8_t b7);
|
||||
uint8_t peek(uint16_t addr);
|
||||
|
||||
8
lua.cpp
8
lua.cpp
@@ -183,6 +183,13 @@ extern "C" {
|
||||
lua_pushinteger(L, strlen(str));
|
||||
return 1;
|
||||
}
|
||||
static int cpp_substr(lua_State *L) {
|
||||
const char* str = luaL_checkstring(L, 1);
|
||||
int start = luaL_checknumber(L, 2);
|
||||
int length = luaL_checknumber(L, 3);
|
||||
lua_pushstring(L, substr(str, start, length));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int cpp_setchar(lua_State *L) {
|
||||
int index = luaL_checkinteger(L, 1);
|
||||
@@ -346,6 +353,7 @@ void lua_init(const char* filename, const bool start_playing) {
|
||||
lua_pushcfunction(L,cpp_ascii); lua_setglobal(L, "ascii");
|
||||
lua_pushcfunction(L,cpp_chr); lua_setglobal(L, "chr");
|
||||
lua_pushcfunction(L,cpp_strlen); lua_setglobal(L, "strlen");
|
||||
lua_pushcfunction(L,cpp_substr); lua_setglobal(L, "substr");
|
||||
|
||||
lua_pushcfunction(L,cpp_setchar); lua_setglobal(L, "setchar");
|
||||
lua_pushcfunction(L,cpp_peek); lua_setglobal(L, "peek");
|
||||
|
||||
Reference in New Issue
Block a user