Hello all, 

I have to admit that I am a C newbie. I want to use Go's slog mechanism 
with variable arguments (for example slog.Warn("message", "argument1", 
"value of argument1"))

The Go function would be something like this:

//export sdLogMessages
func sdLogMessages(level *C.char, message *C.char, arguments []string) {
    goLevel := C.GoString(level)
    goMessage := C.GoString(message)
    var argsAny []any
    for _, arg := range arguments {
        argsAny = append(argsAny, arg)
    }
    switch goLevel {
    case "warn":
        slog.Warn(goMessage,argsAny...)
    }
}

but I have no idea how to create a GoSlice with the char* entries from the 
C part

This is not strictly related to the probelm, but anyhow: My current C part 
is a Lua library:

static int lua_logmessages(lua_State *L) {
  const char *loglevel = luaL_checkstring(L, 1);
  const char *message = luaL_checkstring(L, 2);
  int a = lua_gettop(L); // number of items on the stack 
  char* arg;
 // ***** here I'd like to create either a GoSlice (args) with i char* 
strings
//  or pass char** to the Go function.  
  for (int i = 3; i <= a; i++) {
    arg = luaL_checkstring(L,i);
    printf("arg = %s\n",arg);
  }
  // sdLogMessages(loglevel,message,args);
  return 0;
}

Should I create a GoSlice from char* entries or should I use another way to 
create an array of char* strings?

How would I do that?

Thank you very much
  Patrick


-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/21515a01-d189-44d8-8ba7-cb5bef62fe9bn%40googlegroups.com.

Reply via email to