Close Lua State and Reopen

2019-08-10 15:38发布

问题:

I'm using Lua in android but is not very clear if I can do this:

LuaState L = null;

function loaddata(String data)
{
 if ( L !=null && L.isClosed() == false) 
    L.close();

 L = LuaStateFactory.newLuaState();
 L.openLibs();
 L.LdoString(data);
}

loaddata(string_1)  ;
//and later 
loaddata(string_2);

I want to clear the L and use it with another data, string_2. Will my function L.LdoString(data); have a new data corresponding to string_2? Or will it be string_1 plus string_2 in the L?

回答1:

In your code when you call L.close() you are closing the existing lua state.

You then use LuaStateFactory.newLuaState() to create a new (clean) lua state.

Nothing from a previous call to that function will exit in the new state.

(I'm assuming the functions here work as they would appear to and as the C api functions of similar names function.)



标签: android lua