Skip to content

Instantly share code, notes, and snippets.

@thelink2012
Last active December 14, 2016 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thelink2012/24e78b2b132a4dbe894bab72b8a507d4 to your computer and use it in GitHub Desktop.
Save thelink2012/24e78b2b132a4dbe894bab72b8a507d4 to your computer and use it in GitHub Desktop.
  • Feature Name: require
  • Start Date: 11/11/2016

Summary

A feature to include external GTA3script files into the compilation process.

Motivation

File inclusion is essential for modularity, unfortunately custom scripts do not have access to file includers such as GOSUB_FILE or LAUNCH_MISSION. As such, REQUIRE is proposed.

Detailed design

ID Command Name Command Hash Params
None REQUIRE 0x75ebc48c LABEL

REQUIRE is a command which requests its first argument (which is parsed as a filename, independenty of the current compiling script type) to be added to the compilation process. The REQUIRE command itself does not get compiled into the resulting bytecode.

The bytecode of required scripts should be appended after the requiring script or of the main script if required by multiple source files. If multiple require scripts are to be appeneded, the order of request should be respected.

If a mission/streamed script requires a source file which is also required by another mission/streamed script but not a main script/extension or subscript, an error should occur.

Any symbols introduced by required scripts (e.g. used objects and variables) should have their indices respecting the offset on which the required script was compiled into.

Using REQUIRE inside a required file is forbidden.

Example

main.sc:

REQUIRE file.sc
PRINT_HELP HELLO
GOSUB mysub
TERMINATE_THIS_SCRIPT

main/file.sc

mysub:
PRINT_HELP WORLD
RETURN

once compiled, the decompiled script looks like the following:

PRINT_HELP HELLO
GOSUB mysub
TERMINATE_THIS_SCRIPT
mysub:
PRINT_HELP WORLD
RETURN

Drawbacks

Why should we not do this?

Alternatives

Any other alternative?

Unresolved questions

  • Is "end of main script" the end of main.sc or the end of the last subscript?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment