lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

RJP Computing wrote:
I would like to bind two functions that are using polymorphisms in C++, to Lua, is this possible?

    Create( std::string path, std::string section )
Create( std::string hardware, std::string device, std::map<std::string, std::string> hardwareInitSettings )

Simply check for existence of the function's third argument.

int native_Create(lua_State *L) {

  if (lua_isnoneornil(L, 3)) {
    std::string path;
    std::string section;

    path = luaL_checkstring(L, 1);
    section = luaL_checkstring(L, 2);

    Create(path, section);

  } else {
    std::string hardware;
    std::string device;
    std::map<std::string, std::string> hardwareInitSettings;

    hardware = luaL_checkstring(L, 1);
    device = luaL_checkstring(L, 2);
    luaTableToStringMap(L, 3, hardwareInitSettings);

    Create(hardware, device, hardwareInitSettings);
  return 0;