You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@return int
*/
public synchronized static int insertLuaState(LuaState L)
{
int idx;
for (idx = 0 ; idx < states.size() ; idx++)
{
LuaState state = (LuaState) states.get(idx);
if (state != null)
{
if (state.getCPtrPeer() == L.getCPtrPeer())
return idx;
}
LuaStateFactory.java update
/*
*
*
*
*/
package org.keplerproject.luajava;
import java.util.ArrayList;
import java.util.List;
/**
This class is responsible for instantiating new LuaStates.
When a new LuaState is instantiated it is put into a List
and an index is returned. This index is registred in Lua
and it is used to find the right LuaState when lua calls
a Java Function.
@author Thiago Ponte
/
public final class LuaStateFactory
{
/*
*/
private static final List states = new ArrayList();
/**
*/
private LuaStateFactory()
{}
/**
Method that creates a new instance of LuaState
@return LuaState
*/
public synchronized static LuaState newLuaState()
{
int idx = getNextStateIndex();
LuaState L = new LuaState(idx);
int size = states.size();
if (idx>=size ) {//当集合为空的时候 i== 0 && size == 0
states.add(idx, L);
}else if (idx<size && idx >= 0) {//当集合的
states.set(idx, L) ;
} else {
//异常情况
}
return L;
}
/**
*/
public synchronized static LuaState getExistingState(int index)
{
return (LuaState) states.get(index);
}
/**
Receives a existing LuaState and checks if it exists in the states list.
If it doesn't exist adds it to the list.
@param L
@return int
*/
public synchronized static int insertLuaState(LuaState L)
{
int idx;
for (idx = 0 ; idx < states.size() ; idx++)
{
LuaState state = (LuaState) states.get(idx);
}
idx = getNextStateIndex();
int size = states.size();
if (idx>=size ) {//当集合为空的时候 i== 0 && size == 0
states.add(idx, L);
}else if (idx<size && idx >= 0) {//
states.set(idx, L) ;
} else {
//异常情况
}
return idx;
}
/**
*/
public synchronized static void removeLuaState(int idx)
{
int size = states.size();
if (idx<size) {
states.set(idx, null);
}else {
states.add(idx, null);
}
}
/**
Get next available index
@return int
*/
private synchronized static int getNextStateIndex()
{
int i;
for ( i=0 ; i < states.size() && states.get(i) != null ; i++ );
return i;
}
}
The text was updated successfully, but these errors were encountered: