# reflection

Responsible for lua-scripting execution and handling of API access cross-states.
You can use this to also contact other lua_State instances, and create new ones.
Do note you are responsible for spinning up new states.


# Functions

# reflection.is(name: string): boolean

reflection.is(name: string): boolean
  • checks if the current execution is of a named lua_State

# reflection.get(name: string): lua_State?

reflection.get(name: string): lua_State?
  • attempts to locate a lua_State

# reflection.current(): lua_State

reflection.current(): lua_State
  • gets the current lua_State this is executed in

# reflection.all(): {[index: string]: lua_State}

reflection.all(): {[index: string]: lua_State}
  • gets all instances of lua_State and their names

# reflection.name(lua_State* state): string

reflection.name(lua_State* state): string
  • converts a lua_State to its named counterpart

# reflection.execute(source: string, name: string, state?: lua_State): string?

reflection.execute(source: string, name: string, state?: lua_State): string?
  • executes lua on a lua_State or the current active state its in

# reflection.compile(source: string, name: string): function | string

reflection.compile(source: string, name: string): function | string
  • compiles lua on the the current active state its in

# reflection.open(name: string): lua_State

reflection.open(name: string): lua_State
  • spawns a new lua_State instance or returns one if it already exists
-- creates a new lua_State
local state = reflection.open("lua_State.magic")

-- execute lua right onto the stack
reflection.execute([[
    print("new lua_State boys!")
]], "test", state)

-- you can use basic stack manipulation here as well
print("\nprinting this lua_State's stuff")
reflection.stack(function(L)
    L.pushvalue(-10002)
    L.pushnil()
    while L.next(-2) do
        if L.isstring(-2) then
            print(L.getstring(-2))
        end
        L.pop()
    end
end, state)

-- if you really don't need it, you can close it
reflection.close(state)

# reflection.close(state: lua_State)

reflection.close(state: lua_State)
  • destroys a lua_State instance
  • this won't work on games with built-in lua_State instances

# reflection.stack(func: function(api: lua_capi), state?: lua_State): any...

reflection.stack(func: function(api: lua_capi), state?: lua_State): any...
  • creates a temporary bridge between two lua states
  • this is for users with knowledge of Interstellar C Module
-- this is in menu-state or another lua-state
local other_state = reflection.get("other_state")

local res = reflection.stack(function(L)
    L.pushnumber(20)
    local num = L.tonumber(-1)
    L.pop()
    return num
end, other_state)

print(res) -- 20