Giter Club home page Giter Club logo

rosyn's Introduction

Rosyn

Wraps Lua objects over Instances, automates lifecycle with correct execution order, and handles yielding component dependencies in a memory-safe manner.

Example Usage

1. Lifecycle

local Test = {}
Test.__index = Test

function Test.new(Root: Instance)
    return setmetatable({
        _Root = Root;
    }, Test)
end

function Test:Initial()
    print("Initial call on", self._Root:GetFullName())
end

function Test:Destroy()
    print("Destroy call")
end

Rosyn.Register({
    Components = Rosyn.Setup.Tags({
        TestTag = Test;
    });
})

local TestInstance = Instance.new("Model")
TestInstance:AddTag("TestTag")
TestInstance.Name = "TestInstance"
TestInstance.Parent = workspace
-- Output "Initial call on Workspace.TestInstance"
TestInstance:Destroy()
-- Output "Destroy call"

2. Initial Chaining / Dependencies

local Test1 = [class]
local Test2 = [class]

function Test1:Initial()
    print("Test1 Begin")
    task.wait(1)
    print("Test1 Initial")
end

function Test1:Print()
    print("HHH")
end

function Test2:Initial()
    local Test1Component = Rosyn.AwaitComponentInit(self._Root, Test1)
    Test1Component:Print()
    print("Test2 Initial")
end

Rosyn.Register({
    Components = Rosyn.Setup.Tags({
        TestTag1 = Test1;
        TestTag2 = Test2;
    });
})

local TestInstance = Instance.new("Model")
TestInstance:AddTag("TestTag1")
TestInstance:AddTag("TestTag2")
TestInstance.Parent = workspace
-- Output "Test1 Begin"
-- 1s passes
-- Output "Test1 Initial"
-- Output "HHH"
-- Output "Test2 Initial"

Warning

With Roblox deferred events now enabled by default, Rosyn.GetComponent will return nil if called before defer points when an Instance is cloned / created / tagged. Rosyn.AwaitComponentInit(Instance, Component, 0) is advised to avoid this mistake and will yield until the next frame.

rosyn's People

Contributors

tpc9000 avatar zenthial avatar

Stargazers

 avatar

Watchers

James Cloos avatar Ayuka avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.