[FEAT] substr
This commit is contained in:
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