call a LUA function with parametes from BMX in lug

BlitzMax Forums/BlitzMax Programming/call a LUA function with parametes from BMX in lug

AnniXa(Posted 2012) [#1]
Hey, a small question in here about lugi and lua.
Now with an extra topic, sorry =) i thought it where not good to make an extra topic.

I was able to become lugi and lua running and i can execute scipts now.

But when i have the following lua src:

function startevent(event)
  print ("starting event")
  event:say()
end



how can i then run this code from bmx out and pass over a event type, i tried it with this:

(glue code and stuff is all generated)
type event {expose}

   field text:string

   method say()
       print ("event says:"+self.text)
   end method
end type

type luafuncs {expose static noclass}
   method getnextevent()
      local ev:event = new event
      ev.text = " its me!"
      return ev
   end method
end type

'call the lua func "startevent"

local str = "startevent(getnextevent())"
luaL_dostring(luastate,str)


then the lua function "startevent" is running fine, but event is allways nil, so its not passed over correctly :(

what am i making wrong here?
or is there another easyer way to call functions in lua and give them values/objects withound that trick with the getnextevent() call from lua?

Last edited 2012


N(Posted 2012) [#2]
.

Last edited 2012


N(Posted 2012) [#3]
.

Last edited 2012


AnniXa(Posted 2012) [#4]
it works!
Thank you very much, and thank you for lugi at all.


well another related question, is this:

local str = "startevent(getnextevent())"
luaL_dostring(luastate,str)

really the best way to solve this?


N(Posted 2012) [#5]
.

Last edited 2012


AnniXa(Posted 2012) [#6]
so in my case where the function i want to run is "startevent" i should have do it this way:

lua_getglobal(luastate,"startevent") 'push the function
lua_pushbmaxobject(ev) 'push the event object to the stack
lua_pcall(luastate,1,0,0)' run it with 1 argument, 0 returns
lua_pop(luastate,1) 'pop back the func


?


Edit, i tried it now and it works =)
well is the lua_pop at the end right?
should i not pop 2? since i pushed the object and the function?

Last edited 2012

Last edited 2012


N(Posted 2012) [#7]
.

Last edited 2012


N(Posted 2012) [#8]
.

Last edited 2012