sending tables to a lua function

Started by
1 comment, last by Merick Zero 16 years, 1 month ago
I'm trying to call a lua function from freebasic, constructing two temporary tables as the arguments. The problem is that the function is only receiving one of the tables. Can anyone help me out? in this code, "ref" is a reference to the lua table that contains the function, created earlier in the program with the lua_ref statement, the table created from the "inputs" array gets passed just fine, but the table created from the "desiredOutputs" array is ending up as nil on the lua side
sub neural_net.backwardPropagate(inputs() as integer, desiredOutputs() as integer)
   lua_getref(L, ref)  
   if lua_type(L, -1) <> LUA_TTABLE then 
	Print "error with ref"
	sleep
	system
   endif

   lua_pushstring(L, "backwardPropagate")
   lua_gettable(L, -2) 
	
   lua_newtable(L)
	
   for i as integer = lbound(desiredOutputs) to ubound(desiredOutputs)
	lua_pushnumber(L, (i+1))
	lua_pushnumber(L, desiredOutputs(i))
	lua_settable(L, -3)
   next i
    
   lua_newtable(L)

   for i as integer = lbound(inputs) to ubound(inputs)
	lua_pushnumber(L, (i+1))
	lua_pushnumber(L, inputs(i))
	lua_settable(L, -3)
   next i
	
   If lua_pcall(L, 2, 0, 0) <> 0 Then
	print "ERROR:"
	Print *lua_tostring(L, 1)
	Sleep
	system
   End If

end sub
Advertisement
what is the syntax of the function you are trying to call?
I just figured it out with some help from the people in #lua on freenode. Because the function I'm calling is a method, the first table was getting put into the "self" argument, so to fix it I had to push the originating table onto the stack before pushing my argument tables

This topic is closed to new replies.

Advertisement