---
title: "loadstring"
description: "Compiles Luau source without executing it."
---

```lua
loadstring(source: string, chunkName: string? = "ByteInternal"): (function?, string?)
```

---

## Aliases

None.

---

## Arguments

<ParamField body="source" type="string" required>
  Luau source text.
</ParamField>

<ParamField body="chunkName" type="string" default={"\"ByteInternal\""}>
  The name attached to the compiled chunk for diagnostics.
</ParamField>

---

## Returns

<ResponseField name="compiled" type="function?">
  The compiled function, or nil on failure.
</ResponseField>

<ResponseField name="error" type="string?">
  A diagnostic on failure; absent on success.
</ResponseField>

Returns a function on success; nil and a diagnostic on compilation/load failure.

---

## Example

```lua
local fn, err = loadstring("return 6 * 7", "example")
if fn then print(fn()) else warn(err) end
```
