Search code examples
luapremake

Overriding archFromConfig in premake5 alpha12


I'm trying to generate a project for visual studio configured for Ps4. In my project I added this:

require "orbis"

...

platforms { "x64", "ORBIS" }
filter "platforms:ORBIS"
    toolset "Clang"
    targetextension(".elf")
    architecture "Orbis"

and then I wrote a orbis.lua

local p = premake
local vs = p.modules.vstudio

p.api.addAllowed("architecture", { "Orbis" })

local function archFromConfig_cb(base, cfg, win32)
    if cfg.system == "Orbis" or cfg.architecture  == "Orbis" then
        return "ORBIS"
    end
    return base( cfg, win32 )
end

p.override( vs, "archFromConfig", archFromConfig_cb )

My setup was working properly in Premake5 alpha4 but when I update to Premake5 alpha12 I have this error.

orbis.lua:54: unable to override 'archFromConfig'; no such function

I added some print to understand what's appening I have this...

Overriding
Building configurations...
loading modules vsstudio
Running action 'vs2017'...

So, my orbis.lua is loaded before the vsstudio module, so no function is defined yet. What I have done wrong? How do I fix this?

Thanks in advance.


Solution

  • That took a little puzzling. The Visual Studio code has been moved into an internal module, which is only loaded if it is actually needed. You just need to require that module before attempting the override.

    local p = premake
    local vs = require("vstudio")
    
    p.api.addAllowed("architecture", { "Orbis" })
    
    local function archFromConfig_cb(base, cfg, win32)
        if cfg.system == "Orbis" or cfg.architecture  == "Orbis" then
            return "ORBIS"
        end
        return base( cfg, win32 )
    end
    
    p.override( vs, "archFromConfig", archFromConfig_cb )