Jump to content


Photo

Gmlua [v0.4]


  • Please log in to reply
62 replies to this topic

#1 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 01 May 2010 - 03:01 PM

gmLua is a GM wrapper for Lua 5.1.4, it allows you to use external scripts in your game. This is a much better option over external GML which can access everything, whereas gmLua lets you give access to only specific GML features.

This does not work in GameMaker 8.1 or later.

More information is available on gmLua's on Google Code. You can also report problems when using it by clicking the "Issues" tab.

Edited by TheMagicNumber, 04 September 2011 - 10:45 PM.

  • 2

#2 DJ Gman

DJ Gman

    GMC Member

  • New Member
  • 685 posts

Posted 09 May 2010 - 03:48 PM

When you're working with this, can you also make it compatible with gm6?
  • 0

#3 Recreate

Recreate

    Furry

  • GMC Member
  • 2928 posts
  • Version:GM8

Posted 09 May 2010 - 07:14 PM

When you're working with this, can you also make it compatible with gm6?

No. GM6 is now unsupported. Not to mention most pirates use that one because it has no DRM.
  • 0

#4 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 09 May 2010 - 11:41 PM

You shouldn't be using GM6, upgrade if you want this.
  • 2

#5 DJ Gman

DJ Gman

    GMC Member

  • New Member
  • 685 posts

Posted 10 May 2010 - 01:39 PM

Meh, I'll just work with Kofel's old dll then and rewrite the source if i hit any bumps in the dev process.
  • 0

#6 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 10 May 2010 - 07:15 PM

Your choice, I'm not going to support really old versions of Game Maker.
  • 2

#7 Kofel

Kofel

    GMC Member

  • New Member
  • 50 posts

Posted 12 May 2010 - 08:43 PM

Why you don't wanna to support GM6? :(
  • 0

#8 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 13 May 2010 - 10:14 AM

It's not a requirement, or even priority. GM6 users should upgrade.

Edited by TheMagicNumber, 13 May 2010 - 10:14 AM.

  • 3

#9 DJ Gman

DJ Gman

    GMC Member

  • New Member
  • 685 posts

Posted 14 May 2010 - 01:04 AM

Just curious, does your update to gmlua support using coroutines for yielding and resuming in scripts?
  • 0

#10 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 14 May 2010 - 01:50 AM

Well, it should...I don't see why not. Try it out.
  • 2

#11 DJ Gman

DJ Gman

    GMC Member

  • New Member
  • 685 posts

Posted 14 May 2010 - 01:03 PM

What's the difference between luaCall and luaEvent?
  • 0

#12 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 14 May 2010 - 07:16 PM

Call calls a function, Event calls a procedure (no value returned).
  • 2

#13 DJ Gman

DJ Gman

    GMC Member

  • New Member
  • 685 posts

Posted 16 May 2010 - 01:24 AM

Okay so I've been working around with your new dll for the past 2 days or so with gm8 and I can't seem to get the example included in the rar on your google code to work on my pc. It gives me an error of 'Error defining an external function.
'when i call luastart(). It seems it has trouble wth all of the external function definitions you call in LuaStart(). The odd thing is, that I had the example working at work when i first bought gm8 and downloaded it.

EDIT: Well oddly enough the 0.2 version i downloaded as well didn't work either.

Weirdly though I managed to get the current example to work by downloading this rar you had in the old topic and replacing it's functions

http://www.upurload....2917c08b0a1.zip

Edited by DJ Gman, 16 May 2010 - 02:39 AM.

  • 0

#14 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 16 May 2010 - 02:56 PM

Can you go through luaStart() line by line (using show_message()) and tell me which line it gives you the error? If it's line 3, make sure the DLL exists in the same directory, and if needed, set the variable on line 1 to a FULL PATH to it. Remember, you cannot mix different scripts and DLL versions.
  • 2

#15 DJ Gman

DJ Gman

    GMC Member

  • New Member
  • 685 posts

Posted 16 May 2010 - 03:19 PM

Well now... uhhh... it seems the example I just downloaded works now... must be some issue with paths or gm8.
  • 0

#16 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 16 May 2010 - 05:05 PM

You must've opened it in a way that the current directory wasn't correct.
  • 2

#17 DJ Gman

DJ Gman

    GMC Member

  • New Member
  • 685 posts

Posted 22 May 2010 - 02:00 AM

So yeah, I've been working around with your .dll for the past couple of days and I'm wondering if maybe you could rework your code to call registered gm scripts from lua. I've been trying to get a coroutine system set up, so that i can run lua scripts line by line if need be.
What I have is a base lua file that holds a bunch of predefined functions for executing actions. These functions should be called from individual lua files after it's loaded.

So what I'm trying to do is have something like this

function set_dialog_sprite(sprite, direction, location)
	SetDialogSprite(sprite, direction, location);
end

function say(text)
	-- Format the text
	-- Then for each line in the text, do the following stuff.
	
	lockplayer()
	LockEnemies()
	LockNPCs()
	DisableInventory()
	
	SetMessageBox(text);
	pause_script();
end

function exec_script()
end

function resume_script()
	coroutine.resume(script);
end

function pause_script()
	coroutine.yield(script);
end

script = coroutine.create(exec_script);
coroutine.resume(script);


Then in my induvidual lua file, this would be ran.
function exec_script()
		set_dialog_sprite('Nicolas_mugshot_1',1,0);
		say('derp');
		play_sound(whatever.ogg);
end


My only problem is that I can't seem to work with coroutines this way because I keep getting this error from lua
attempt to yield across metamethod/C-call boundary

I think this happens because I'm directly using the registered gm scripts i made, directly in the stack of the coroutine. Which it doesn't agree with. I've even tried using luaJIT instead of the standard library you provided, which makes use of coco(http://coco.luajit.org/) which is supposed to handle this sort of scenario and allow you to yield scripts i assume.

What I've seen done though, and what I've been basing my coroutine system on, is that in the xlua extension for mmf2 that uses luaJIT, the author put in a wrapper function in c to lua called DoCall() which would basically take the name of a registered MMF2 function and it's arguments and execute it, rather than directly registering the MMF2 function.

which looks something like this
DoCall("SetDialogSprite",sprite, direction, location);
as opposed to
SetDialogSprite(sprite, direction, location);

This is the example of the wrapper function from c the author gave me
// Register DoCall function
	lua_pushcfunction(state, LuaState::LuaC_DoCall);
	lua_setglobal(state, "DoCall");

int LuaState::LuaC_DoCall (lua_State *L) {
	LuaState* state = LGLOB->GetStateByState(L);
	if (state == NULL) return 0;

	return state->stack.CallMMFFunction(MF_FUNCTION_GROUP_DEF, L);
}

He also said

I seem to recall some issue with corotines at one point but I don't exactly remember what it was.I think it might have to do with coroutines having a different lua_State* pointer associated with them, and I was using the wrong one. I had to change my implementation of CallMMFFunction to accept the Lua State passed to DoCall (as is seen in the code snippet I posted above) -- before it used its own internally cached version.



So I'm wondering if possibly you could implement the same kind of thing into your code. I've downloaded, studied, and built the source you have on google code, but honestly I'm not as familiar with your code as you would be... which is why it would help me so much and improve the functionality of your dll if you could please add this in.

P.S. Sorry for the wall of text lol, you have no idea how much I've been battering my brain out over this heh.

Edited by DJ Gman, 22 May 2010 - 02:04 AM.

  • 0

#18 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 22 May 2010 - 02:31 AM

Right now, you can only call GM scripts (not function) from Lua when registered. I don't exactly know much about Lua so if you could give me information about what you want, it'd be great.
  • 2

#19 DJ Gman

DJ Gman

    GMC Member

  • New Member
  • 685 posts

Posted 22 May 2010 - 02:49 AM

Well, from what I understand, there needs to be a middleground between GM, C, and lua.

what I think retriever2 does with xlua is that he first creates a C function to get the state of the lua function DoCall, without actually calling any c function in lua.

So basically DoCall("ScriptName",arg1,arg2) in lua, pushes a bunch of arguments into the lua stack that the C function is supposed to interpret
then the C function takes that information and calls a GM script with those arguments that we provided in lua without having to register those individual game maker scripts into lua.

This might actually be a pretty feasible way of getting Game Maker's functions into the dll as well when you think about it...

Edited by DJ Gman, 22 May 2010 - 02:56 AM.

  • 0

#20 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 22 May 2010 - 03:42 PM

So you want me to make a function that can basically call any GM function with any params? It might be a bit unsafe, it can corrupt the stack. It's a fair method, though. I may do it, seeing as I've modded FFI and fixed some bugs so I know a bit about this. I'll look into it.

Edit: I'm going to add two functions, one will return the function pointer to a GM function, and another will call a function by pointer. Any suggestions?

Edited by TheMagicNumber, 22 May 2010 - 10:42 PM.

  • 2




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users