foxygit / fake-08-xbox360 Log in
commit ef12b93304143b7c28509a92011c1126ee2919f1
Author:     DPS2004 <dpsophinos@gmail.com>
AuthorDate: Mon Mar 21 13:45:34 2022 -0400
Commit:     DPS2004 <dpsophinos@gmail.com>
CommitDate: Mon May 2 09:40:54 2022 -0400

    get line from file (to get first 2 lines for menu)
---
 source/picoluaapi.cpp | 20 +++++++++++++++++++-
 source/picoluaapi.h   |  2 ++
 source/vm.cpp         | 21 +++++++++++++++++++++
 source/vm.h           |  4 +++-
 4 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/source/picoluaapi.cpp b/source/picoluaapi.cpp
index 6dd642e..aa7379f 100644
--- a/source/picoluaapi.cpp
+++ b/source/picoluaapi.cpp
@@ -1346,6 +1346,7 @@ int setsetting(lua_State *L) {
     return 1;
 }

+
 int loadlabel(lua_State *L) {

 	const char * cartname = "";
@@ -1359,4 +1360,21 @@ int loadlabel(lua_State *L) {

 	_vmForLuaApi->loadLabel(filename, mini, minioffset);
 	return 1;
-}
\ No newline at end of file
+}
+
+
+int getlualine(lua_State *L) {
+	const char * cartname = "";
+	if (lua_isstring(L, 1)){
+        cartname = lua_tolstring(L, 1, nullptr);
+    }
+	std::string filename = cartname;
+
+	int linenumber = lua_tonumber(L,2);
+
+	std::string resultstring = _vmForLuaApi->getLuaLine(filename, linenumber);
+
+	lua_pushstring(L, resultstring.c_str());
+
+	return 1;
+}
diff --git a/source/picoluaapi.h b/source/picoluaapi.h
index ff91ba4..ffc47f9 100644
--- a/source/picoluaapi.h
+++ b/source/picoluaapi.h
@@ -109,6 +109,8 @@ int setsetting(lua_State *L);

 int loadlabel(lua_State *L);

+int getlualine(lua_State *L);
+
 //system functions

 int rnd(lua_State *L);
diff --git a/source/vm.cpp b/source/vm.cpp
index 675b742..303ed02 100644
--- a/source/vm.cpp
+++ b/source/vm.cpp
@@ -179,6 +179,8 @@ bool Vm::loadCart(Cart* cart) {
 	//label
 	lua_register(_luaState, "__loadlabel", loadlabel);

+	lua_register(_luaState, "__getlualine", getlualine);
+
     //register global functions first, they will get local aliases when
     //the rest of the api is registered
     //graphics
@@ -1090,4 +1092,23 @@ void Vm::loadLabel(std::string filename, bool mini, int minioffset) {
 	}
 	delete labelcart;

+}
+
+std::string Vm::getLuaLine(string filename, int linenumber) {
+
+	auto cartDir = _host->getCartDirectory();
+    Cart *luacart = new Cart(filename, cartDir);
+	std::string luastr = luacart->LuaString;
+
+	std::string line;
+	std::istringstream luastream(luastr);
+
+	while (linenumber-- >= 0){
+		std::getline(luastream,line);
+	}
+
+	delete luacart;
+
+	return line;
+
 }
\ No newline at end of file
diff --git a/source/vm.h b/source/vm.h
index cef96d9..4c29f6b 100644
--- a/source/vm.h
+++ b/source/vm.h
@@ -152,7 +152,9 @@ class Vm {

 	//label
 	void loadLabel(string filename, bool mini, int minioffset);
-
+
+	string getLuaLine(string filename, int linenumber);
+
     string getCartBreadcrumb();
     string getCartParam();
 };