Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

iOS - How can i pass launch args to main.lua?
Started by otkmember Jan 29 2020 08:29 PM

4 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

otkmember

[GLOBAL: userInfoPane.html]
otkmember
  • Observer

  • 9 posts
  • Corona SDK

The docs says that "willLoadMain" method execute before main.lua will be called.

so, i want to pass some data as an argument table, like a product version, sandbox or debug bool values, etc.

 

is the any way can i perform it?

 

or, maybe i could set table in _G from this point? its fine too.



[TOPIC: post.html]
#2

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Corona Geek

  • 1,176 posts
  • Corona SDK

If I remember correctly, all you need to do to get launch arguments is to put the following line of code in your main.lua.

local launchArgs = ...

I think that the only way you can pass those launchArgs was via URLs or notifications, but it's been such a long while that things may have changed.



[TOPIC: post.html]
#3

otkmember

[GLOBAL: userInfoPane.html]
otkmember
  • Observer

  • 9 posts
  • Corona SDK

If I remember correctly, all you need to do to get launch arguments is to put the following line of code in your main.lua.

local launchArgs = ...

 

this part is familiar to me, the question is how to put the lua table in those args.

maybe it has some function like Corona::Lua::DispatchRuntimeEvent(L, ...); which i can call from AppCoronaDelegate file.

it probably must have one.



[TOPIC: post.html]
#4

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Corona Geek

  • 1,176 posts
  • Corona SDK

I am probably misunderstanding what you mean, but you can add tables to it in main.lua via

local launchArgs = { ... }
launchArgs.myTable = {}

If you want to include some extra data to the launchArgs before main.lua, then you'll probably need to dig into Corona source. As far as I remember, only way to get anything to launchArgs is by starting a Corona app via notifications or via URL.



[TOPIC: post.html]
#5

otkmember

[GLOBAL: userInfoPane.html]
otkmember
  • Observer

  • 9 posts
  • Corona SDK

so, for now i find out how to set table in _G and use it.

here is piece of my code 

lua_newtable(L);
lua_setglobal(L, "_CONST");
lua_getfield(L, LUA_GLOBALSINDEX, "_CONST");

for ( NSString *key in constants ){

	if ( [constants[key] isKindOfClass:[NSString class]] ){
		const char *var = [constants[key] UTF8String];
		lua_pushstring(L, var);
		lua_setfield(L, -2, [key UTF8String] );
	}

	if ( [constants[key] isKindOfClass:[NSNumber class]] ){
		lua_pushnumber(L, [constants[key] intValue]);
		lua_setfield(L, -2, [key UTF8String] );
	}
}

lua_pushboolean(L, (isProduction) ? 1 : 0 );
lua_setfield(L, -2, "PRODUCTION" );
lua_pop(L, 1);

but anyway, if the solution with launch args will appear, please, let me know.




[topic_controls]
[/topic_controls]