> ## Documentation Index
> Fetch the complete documentation index at: https://docs.projectreal.gg/llms.txt
> Use this file to discover all available pages before exploring further.

# loadstring

> Compiles a Luau source string and returns the loaded function. If loading fails, it returns nil and an error message. The returned function is not executed automatically.

<div className="real-function-page">
  ```lua theme={null}
  loadstring(source: string, chunkName?: string): function | nil | string | nil
  ```

  ## 引数

  <ParamField path={"source"} type={"string"} required>
    Luau source string to compile. Embedded null bytes after the first null are not preserved.
  </ParamField>

  <ParamField path={"chunkName"} type={"string"}>
    Optional chunk name used for error reporting. Defaults to "@" when omitted or nil.
  </ParamField>

  ## 戻り値

  <ResponseField name={"chunk"} type={"function | nil"}>
    Loaded function when compilation and loading succeed, otherwise nil.
  </ResponseField>

  <ResponseField name={"errorMessage"} type={"string | nil"}>
    Load error message when loading fails. Not returned on success.
  </ResponseField>

  ## 例

  source text をコンパイルし、発生し得る compiler error を処理します。

  ```lua theme={null}
  local chunk, message = loadstring("return 6 * 7", "ExampleChunk")

  if chunk then
      print(chunk())
  else
      warn(message)
  end
  ```
</div>
