Snowball Docs
SocialsContributeTry out online!Standard Library
  • 👋Welcome to snowball!
  • Overview
    • 🐈Why Snowball
    • ✨Language Features
  • fundamentals
    • 🛠️Getting started
    • 📝Installation
      • ‼️Common install issues
    • 👶Hello world!
  • language reference
    • 🌐Global Scope
    • 🤖Functions
      • 🐣Basic syntax
      • 😵Function Generics
      • ❓External functions
      • 🔧Function Attributes
      • 💢LLVM Functions
      • 🚪Program Entries
    • 🎭Types
      • 🔢Primitive types
      • 🔀Reference types
      • ☝️Pointer types
      • 🔓Mutability
      • ⁉️Type generics
      • 🔖Type aliases
      • 🚯Unknown pointer type (void pointers)
    • 🔄Casting
      • 🔐Mutability casting
      • 🦺Dynamic casting
      • 👨‍🎓Type conversions
    • 🏗️Classes
      • 💼Members
      • 🔒Access qualifiers
      • 🛑Final classes
      • 🍧Abstract classes
    • 🔏Access qualifiers
    • ⚒️Macros
      • ✨Builtin macros
    • 🔫Unsafe snowball
    • 😴Generics
    • 🌳Code Flow
      • ☝️If statements
    • 📦Modules
      • 👉Using Statement
  • snowball cli usage
    • 💻CLI usage and parameters
    • 🧪Testing mode
  • Confy
    • ⚙️Getting Started
    • 🐈Snowball's Schema
  • Reky Package Manager
    • 📦Getting Started
  • coding style
    • 💅The desired standard
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
  1. language reference
  2. Functions

External functions

In Snowball, you can declare and use external functions that are implemented outside of your current module or translation unit. This allows you to interface with code written in other programming languages or external libraries. Here are a couple of examples of declaring and using external functions in Snowball:

External functions that are not declared as Snowball must be declared as unsafe!

  1. Basic External Function Declaration:

external "C" unsafe func example();

In this example, example is declared as an external function. You can use this declaration to call the function without providing the implementation within your Snowball code. The implementation example is expected to be provided by an external source, such as another module or library.

  1. External Function Declaration with Custom Name:

external "C" unsafe func "my.weird$function" as my_function();

In this example, my_function is declared as an external function with a custom name "my.weird$function". This allows you to specify a specific name for the external function that might differ from its original name or naming conventions. You can then use my_function it to call the function in your Snowball code.

When declaring external functions, it's important to ensure that the function name and signature match the actual implementation in the external code. This includes the function name, the number and types of arguments, and the return type.

External functions enable Snowball to interact with external code seamlessly, extending the capabilities of your programs by leveraging existing libraries or external functionality.

You don't need to specify argument names in external functions, for example:

external func foo(i32, String);

Types of External Linkage Types

  • "C" - This is the same as external func foo(); whatever the default your C compiler supports.

  • "System" - Usually the same as extern "C", except on Win32, in which case it's "stdcall", or what you should use to link to the Windows API itself

  • "Snowball" - The default ABI when you write a normal fn foo() in any snowball code.

PreviousFunction GenericsNextFunction Attributes

Last updated 1 year ago

Was this helpful?

🤖
❓