Skip to content

Serious bug: char*-valued functions that return nullptr make system go BOOM #107

@rpatters1

Description

@rpatters1

I have finally nailed down the actual situation that is causing a breaking change in my scripts. I apologize for two previous long-winded issues that were wrong (and now closed).

Consider this class and its registration:

class foo
{
public:
   foo() {}
   const char * nullconst() { return nullptr; }
   char * null() { return nullptr; }
   void twochars (const char* one, const char* two = nullptr)
   {
      std::string one_two = one;
      if (two) one_two += " another parameter was provided: " + two;
   }
};

   luabridge::getGlobalNamespace(L)
     .beginNamespace("foobar")
        .beginClass<foo>("foo")
           .addConstructor<void(*)(void)>()
           .addFunction("nullconst", &foo::nullconst)
           .addFunction("null", &foo::null)
           .addFunction("twochars", &foo::twochars)
        .endClass()
     .endNamespace();

Now consider the following Lua:

local foo = foobar.foo()
local nullconst = foo:nullconst() -- nullconst comes back nil on LB2 but "" on LB3: this is a breaking change
local null = foo:null() -- null doesn't come back. system goes >>BOOM<< on both LB2 and LB3

See comments. My opinion is that both local variables nullconst and null should be nil after this code runs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingsevere

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions