lua-users home
lua-l archive

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


I have a situation that I feel others must have come across before but I
am unable to find any solution to my problem in the archive or the docs.

What I would like to do is to overload a registration of a c function.

What I would like to write in c is something like:

int myhandler( lua_State* L )
{
  int n_returns = 0;
  if(strcmp(lua_tostring(L,0),"foo")==0)
  {
    ... do stuff for function foo
  }
  else if(strcmp(lua_tostring(L,0),"fun")==0)
  {
    ... do stuff for function fun
  }
  return n_returns;    /* would be set by something above
}

So I envision lua_tostring(L,0) retrieving something analogous to what
argv[0] is in the parameters to a program - the program name.  That way
I could write the following registrations:

  lua_register(L,"foo",myhandler);
  lua_register(L,"fun",myhandler);

Why would I want to do this?  Well, the data type that I wish to use lua
to handle in scripts has a variable number of entry points which can be
determined programmatically but are not feasible to provide a separate c
function for them at compile time.

I hope the question is lucid and my quandry clear.  Thank you for any
interest in answering it.  Is this possible?

All the best,
Mark.