C++ Scripting: Part 23 – Base Type APIs

Tags: ,

Now that we have complete support overriding everything—methods, properties, indexers, events—that can be overridden in a base class or interface, there’s a bit of tidying up to do. In today’s article, we’ll take steps to make base types much more useful by inserting them into their proper place in the type hierarchy.

Read the rest of this article »

No Comments

C++ Scripting: Part 22 – Full Base Type Support

Tags: , , ,

Today we’ll complete our ability to use C++ classes to derive from C# classes and implement C# interfaces. So far we’ve been able to override methods, properties, and indexers. Today we’ll add the ability to override events and derive from classes that don’t have a default constructor.
Those are the last two pieces of the puzzle that will allow us to derive from any C# base type with a C++ class. Read on for all the details about how this works.

Read the rest of this article »

No Comments

C++ Scripting: Part 21 – Implement C# Properties and Indexers in C++

Tags: , ,

Part 19 of this series started to allow our C++ game code to derive from C# classes and implement C# interfaces. The first step was to override methods as they’re the most common. Today we’ll tackle the second-most common: properties. We’ll also handle indexers, which are like properties with more parameters. Read on to see how to use this and how it works behind the scenes.

Read the rest of this article »

No Comments

C++ Scripting: Part 20 – Performance Improvements

Tags: , , ,

The last time we looked at performance was way back in part four of the series. Ever since then we’ve been relentlessly adding more and more features to the C++ scripting system. So today we’ll take a break from feature additions to improve the system’s performance in a couple of key areas.

Read the rest of this article »

No Comments

C++ Scripting: Part 19 – Implement C# Interfaces with C++ Classes

Tags: , , , ,

Implementing interfaces and deriving from classes is commonplace in many codebases. Today we’ll make it so C++ classes can implement C# interfaces and derive from C# classes. This means our C++ game code will be able to implement custom IComparer classes for sorting a List and derive custom EventArgs for dispatching in events. Read on to see how this is implemented and how to use it in our projects.

Read the rest of this article »

No Comments

C++ Scripting: Part 18 – Array Index Operator

Tags: ,

When we covered arrays in part 14, we skipped implementing the [] operator with them. Instead, we opted for a simpler pair of GetItem and SetItem functions. Today we’ll address that oversight so our C++ game code can index arrays just like in C#.

Read the rest of this article »

No Comments

C++ Scripting: Part 17 – Boxing and Unboxing

Tags: , , , , ,

The GitHub project is closing in on supporting all the “must have” features. Today’s article tackles “boxing” and “unboxing” so our C++ game code will be able to convert types like int into an object and then convert an object back into an int. Usually we want to avoid this because it creates garbage for the GC to later collect and ruins type safety, but sometimes an API like Debug.Log insists that we pass it an object. Read on to see how to use boxing and unboxing in C++!

Read the rest of this article »

No Comments

C++ Scripting: Part 16 – Events

Tags: , , , ,

Last week’s article covered delegates, so it’s only natural that we follow up this week by covering events. Supporting delegates has laid a good foundation for supporting events, so let’s dive in and see how to implement and use them in C++.

Read the rest of this article »

No Comments

C++ Scripting: Part 15 – Delegates

Tags: , , , , ,

This week’s article adds another major feature to the C++ scripting system: delegates. These are vital so C++ game code can use features like Unity’s UI system (a.k.a. UGUI). Without them, we wouldn’t be able to handle button clicks or other UI events. So read on to learn how these were implemented in the GitHub project.

Read the rest of this article »

No Comments

C++ Scripting: Part 14 – Arrays

Tags: ,

The series continues by adding support for a major feature: arrays. These are used very frequently throughout the Unity and .NET APIs and the lack of support for them has been a big missing piece of the puzzle for most games. The GitHub project has been updated to support single- and multi-dimensional arrays. Read on to learn how this support was implemented!

Read the rest of this article »

No Comments