Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

GMS functions return nil

A topic by Anumania created Aug 04, 2022 Views: 204 Replies: 6
Viewing posts 1 to 7

My exact runtime version is 2.3.3.437
I'm setting up Apollo for use in a game, and it appears that gamemaker user defined functions added to lua through lua_add_function only allow for real and string return types when used in lua, all other gamemaker types return nil. Documentation says lua should be able to handle types other than real and string (method, struct, array), and it does just fine when its being passed these types as function arguments. If this is intentional behavior i can find a workaround, but documentation does not say anything about this restriction.

Developer

From what I can see, I have the following changes since the current public release:

  • In apollo_buffer.gml, else if (is_method(v)) { branch was moved in front of else if (is_struct(v)) { since methods now count as structs.
  • In apollo_ref.gml, else if (is_struct(_val)) _kind = 1; is now else if (is_struct(_val) && !is_method(_val)) _kind = 1; for same reason.

This is my test code for methods:

function scr_test_methods(q) {
	//#mark methods
	lua_add_code(q, @'function f(m)
		return m()
	end');
	var fn = function() {
		return "OK!"
	}
	assert(lua_call(q, "f", fn), "OK!")
	assert(lua_call(q, "f", lua_byref(fn)), "OK!")
	
	var fn2 = function() {
		return function() { return "OK2!" }
	}
	lua_add_function(q, "get_ok2", fn2);
	lua_add_code(q, @'function f2(m)
		local _f = get_ok2()
		return _f()
	end');
	assert(lua_call(q, "f2", fn), "OK2!")
}

Thanks to recent runtime updates, the extension can now be rewritten completely but I haven’t gotten around to it yet.

(3 edits)

I made the changes you listed to see if it would help and no luck.

 
I'm logging the type that it sends to lua and for all of your test methods it is detecting them as methods and adding them correctly to the buffer 


 i will check around and see if im doing anything that could be interfering. I checked the apollo source code file to try and debug from the dll side and im not really sure if im supposed to be able to compile it but im not having any luck.

Developer

Make sure that you’ve imported Apollo-GMS2.3.yymps and not Apollo-GMS2.yymps - you can use the 2.2 version in 2.3, but it does not have struct/method support because those didn’t exist in 2.2.5

(1 edit)

it seems like the 64 bit dll does not work, but when reverting to the 32 bit one, all tests pass. is the 64 bit dll an older version?
 

I downloaded the minifix and it looks like the 64 bit dll from that version works properly.
thank you for the support!

Developer

I have now uploaded a new version of the extension with “fresh” Windows/Mac/Linux binaries to be extra sure.