Exemplo n.º 1
0
void LuaState::setGlobal( const std::string& name, bool value )
{
    getGlobalTable();
    lua_pushboolean( m_lua, ( int ) value );
    lua_setfield( m_lua, -2, name.c_str()  );
    lua_pop( m_lua, 1 );
}
Exemplo n.º 2
0
void LuaState::setGlobal( const std::string& name, const std::string& value )
{
    getGlobalTable();
    lua_pushstring( m_lua, value.c_str() );
    lua_setfield( m_lua, -2, name.c_str()  );
    lua_pop( m_lua, 1 );
}
Exemplo n.º 3
0
void LuaState::setGlobal( const std::string& name, const char* value, unsigned int length )
{
    getGlobalTable();
    lua_pushlstring( m_lua, value, length );
    lua_setfield( m_lua, -2, name.c_str()  );
    lua_pop( m_lua, 1 );
}
Exemplo n.º 4
0
void LuaState::setGlobal( const std::string& name, void* value )
{
    getGlobalTable();
    lua_pushlightuserdata( m_lua, value );
    lua_setfield( m_lua, -2, name.c_str()  );
    lua_pop( m_lua, 1 );
}
Exemplo n.º 5
0
void LuaState::setGlobal( const std::string& name, unsigned int value )
{
    TRACE_ENTERLEAVE();
    getGlobalTable();
    lua_pushinteger( m_lua, value );
    lua_setfield( m_lua, -2, name.c_str() );
    lua_pop( m_lua, 1 );
}
Exemplo n.º 6
0
void LuaState::getGlobalTable()
{
    lua_getglobal( m_lua, "__leda" );
    if ( lua_isnil( m_lua, -1 ) )
    {
        lua_pop( m_lua, 1 );
        //
        //  create new table if not set
        //
        lua_newtable( m_lua );
        lua_setglobal( m_lua, "__leda" );
        getGlobalTable();
    }
}
Exemplo n.º 7
0
unsigned int LuaState::getGlobal( const std::string& name )
{
    unsigned int result = 0;
    
    getGlobalTable();
    
    if ( lua_istable( m_lua, -1 ) )
    {
        lua_getfield( m_lua, -1, name.c_str() );
        result = lua_tointeger( m_lua, -1 );
        lua_pop( m_lua, 1 ); 
    }
    lua_pop( m_lua, 1 ); 

    return result;
}
Exemplo n.º 8
0
Variables ScriptManager::callFunction(const Common::UString &name, const Variables &params) {
	assert(!name.empty());
	assert(_luaState && _regNestingLevel == 0);

	std::vector<Common::UString> parts;
	Common::UString::split(name, '.', parts);
	if (parts.empty()) {
		error("Lua call \"%s\" failed: bad name", name.c_str());
		return Variables();
	}

	const Common::UString funcName = parts.back();
	parts.pop_back();

	if (parts.empty()) {
		return getGlobalFunction(funcName).call(params);
	}

	TableRef table = getGlobalTable(parts[0]);
	for (uint32 i = 1; i < parts.size(); ++i) {
		table = table.getTableAt(parts[i]);
	}
	return table.getFunctionAt(funcName).call(params);
}
Exemplo n.º 9
0
void GCObjectManager::performFullGC() {
    vector<GCObject*> unscaned;
    {
        auto vm = LuaVM::instance();
        if (auto gtable = vm->getGlobalTable()) {
            unscaned.push_back(gtable->gcAccess());
        }
        if (auto stack = vm->getCurrentStack()) {
            unscaned.push_back(stack->gcAccess());
        }
    }

    while (!unscaned.empty()) {
        GCObject *o = unscaned.back();
        unscaned.pop_back();
        o->gcState = GCObject::GCS_Scaned;
        switch (o->objType) {
        case GCObject::OT_Table:
            static_cast<LuaTable*>(o)->collectGCObject(unscaned);
            break;
        case GCObject::OT_Function:
            static_cast<Function*>(o)->collectGCObject(unscaned);
            break;
        case GCObject::OT_Stack:
            static_cast<LuaStack*>(o)->collectGCObject(unscaned);
            break;
        case GCObject::OT_String:
            break;
        default:
            ASSERT(0);
        }
    }

    {
        GCObject *obj = m_headObj;
        m_headObj = NULL;
        m_objCount = 0;
        while (obj != NULL) {
            GCObject *temp = obj;
            obj = obj->next;
            if (temp->gcState == GCObject::GCS_Unaccess) {
                switch (temp->objType) {
                case GCObject::OT_Table:
                    static_cast<LuaTable*>(temp)->destroy();
                    break;
                case GCObject::OT_String:
                    static_cast<LuaString*>(temp)->destroy();
                    break;
                case GCObject::OT_Stack:
                    static_cast<LuaStack*>(temp)->destroy();
                    break;
                case GCObject::OT_Function:
                    static_cast<Function*>(temp)->destroy();
                    break;
                default:
                    ASSERT(0);
                }
            } else {
                ASSERT(temp->gcState == GCObject::GCS_Scaned);
                ++m_objCount;
                temp->gcState = GCObject::GCS_Unaccess;
                temp->next = m_headObj;
                m_headObj = temp;
            }
        }
    }

    LuaVM::instance()->getStringPool()->onFullGCEnd(m_headObj);
}