I'm trying to use a lua state within C++ and i need to pass it a str from C++, how ever when i try to call my function i wrote in lua, i get the error attempted to call nil value. It compiles straight into the lua environment, but when i type the expression in i get the error.
int main(int argc, char** argv){
lua_State *L;
L = luaL_newstate();
string buff;
const char* finalString;
luaL_openlibs(L);
luaL_dofile(L,argv[1]);
getline(cin, buff);
lua_getglobal(L, "InfixToPostfix");
lua_pushstring (L, buff.c_str());
lua_pcall(L, 1, 1, 0);
finalString = lua_tostring(L, -1);
printf("%s\n", finalString);
lua_close(L);
}
from lua file:
function InfixToPostfix(str)
print("before for loop")
for i in string.gmatch(str, "%S+") do
it wont reach the print out before displaying error