Pass object custom property to material via OSL script

I was looking for a way to pass custom values for a large number objects to the object’s material, without having to define a new material for each object. The only way I found online (for example here) was using the object’s Pass Index, but that only allows for a single value to be passed.
An alternative method is to use the object’s name and an OSL script. It is not very elegant, but allows for setting multiple values.
In the screenshot below the three cubes share the same material. The R_G_B values have been set in the object names. The OSL script in the script node gets the object name, splits the name in substrings and convert the substrings the values, which are combined to the color output of the script node.

Here is the OSL script:

#include "stdosl.h"

shader color_from_name (
    output color name_color = color(0,0,0)
)

{
    string name_string = "";
    getattribute("geom:name", name_string);
    
    string string_array[4];
    int number_of_strings = split(name_string, string_array, "_");
    
    float R = stof( string_array[1] );
    float G = stof( string_array[2] );
    float B = stof( string_array[3] );
    
    name_color = color(R,G,B);
}

A python script could be used to set the object names, or add the object’s custom properties to the object name, something like:

obj = bpy.context.object
obj.name = "Cube_" + str(obj["prop1"]) + "_" + str(obj["prop2"]) + "_" + str(obj["prop3"])