Jump to content


Photo

Gmlua [v0.2 Last Update: 26 December 2009]


  • This topic is locked This topic is locked
134 replies to this topic

#1 Kofel

Kofel

    GMC Member

  • New Member
  • 50 posts

Posted 05 March 2009 - 07:10 AM

Last update: 26 December 2009
Version: 0.2

gmLua


It's Lua interpreter wrapper for Game Maker which make able to execute Lua scripts, it help you with making your game moddable.

Using standard execute_string isn't too much expensive and safe. In gmLua you decide which GM functions and scripts will be avaiable in Lua.

Manual:
  • luaNew() Initalize Lua interpeter for that object in which you call it, returns pointer
  • luaRegister( Pointer, LuaFunctionName, scriptPointer ) register your script as Lua function, or:
  • luaRegister( Pointer, GMFunctionName ) make able to call GM function in Lua, such as: luaRegister( Pointer, "show_message" );
  • luaLoadFile( Pointer, FileName ) Load a Lua script file
  • luaEvent( Pointer, EventName, ... ) Calls a function in Lua code called like EventName, it takes also up to 14 arguments
  • luaCall( Pointer, LuaFunctionName, ... ) Calls a Lua function
  • luaSetErrorScript( Pointer, GMScriptName ) Set your script as a error handle instead of classic show_message
  • luaDestroy( Pointer ) You don't need solution? :> // You don't have call it ;o

Package includes Lua dll, example and gmLua binary.

If you found any bug please post it here: http://code.google.c...lua/issues/list

Download:

More info: gmLua at Google Code

Thanks to Snake_PL for make GMAPI <3

Source code is avaiable on SVN:

svn checkout http://gmlua.googlecode.com/svn/trunk/ gmlua


GMAPI ( both gmLua ) for now works only with GM 6 and 7. No 8.0 support.

gmLua now is developed only by TheMagicNumber.

Greetings,
Kofel.

Edited by KC LC, 01 May 2010 - 10:27 AM.

  • 1

#2 allong

allong

    GMC Member

  • GMC Member
  • 191 posts

Posted 05 March 2009 - 10:44 AM

Wow, that's pretty cool. Could it be as extensive as the functions used by the Half-life2 source engine or World Of Warcraft? Please post more info on possibilities and what the Dll allows you to do
  • 0

#3 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 05 March 2009 - 11:25 AM

You can use all the functions and features in Lua, but you can't extend on it.

And yes, make an example. :blink:
  • 0

#4 Kofel

Kofel

    GMC Member

  • New Member
  • 50 posts

Posted 05 March 2009 - 03:19 PM

Thanks for comments.

Simply, DLL allow you to create flexible game or game server for which user/developer can make nice scripts and events. :>

Mechanism is pretty cute, developer make a hooks in own game, example: ( step event )
if( player_damage ){	if( lua_event( "onPlayerDamage", instance_id, other_player_id ) ) //First argument is attacked player ( hmm... simply instance id ) and second is enemy which attack you ( also instance id )	{ // Instructions below doesn't be executed if we return 1; in Lua function :>		player.health -= 100;	}}

getPlayerHealth script in GM:
return argument0.health;

Create step:
lua_state();lua_register( "getPlayerHealth", getPlayerHealth );lua_load( "script.lua" );

And Lua code:
function onPlayerDamage( player, attacker )	if( getPlayerHealth( player ) < 99 ) then		return 1	endend

That example is so simple. :> I will create other example in future ( more advanced ), I think in this week.
  • 0

#5 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 05 March 2009 - 08:34 PM

Put it in a file, and does lua_event() just call a function in the Lua script?
  • 0

#6 Kofel

Kofel

    GMC Member

  • New Member
  • 50 posts

Posted 06 March 2009 - 07:42 AM

Yes :>
  • 0

#7 Hach-Que

Hach-Que

    RoketGames Admin

  • New Member
  • 1490 posts

Posted 06 March 2009 - 09:40 AM

I tried to make a test example to see how fast it ran and the game just closed instantly on run :/
  • 0

I don't visit these forums (and I haven't for quite some time). You can

see my latest community projects at the Redpoint Blog.


I never thought I'd see myself writing the above.. :(


#8 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 06 March 2009 - 11:06 AM

Can you put the examples in editable files instead of posting events and code on the forum?

@Hach-Que:
Was it that fast or that bad...
  • 0

#9 Hach-Que

Hach-Que

    RoketGames Admin

  • New Member
  • 1490 posts

Posted 06 March 2009 - 12:22 PM

There's no game_end() call in my code. It just causes the game to crash.
  • 0

I don't visit these forums (and I haven't for quite some time). You can

see my latest community projects at the Redpoint Blog.


I never thought I'd see myself writing the above.. :(


#10 Kofel

Kofel

    GMC Member

  • New Member
  • 50 posts

Posted 06 March 2009 - 04:00 PM

Damn it! I forgot, that works only with GM 7, I promise I'll post fixed version with GM 6 ( 5 maybe ) with example today. ;>


EDIT: Fixed version in this same link. I hope it will work.

Edited by Kofel, 06 March 2009 - 11:15 PM.

  • 0

#11 Hach-Que

Hach-Que

    RoketGames Admin

  • New Member
  • 1490 posts

Posted 07 March 2009 - 02:04 AM

There's only one problem with that solution. I am using Game Maker 7.
  • 0

I don't visit these forums (and I haven't for quite some time). You can

see my latest community projects at the Redpoint Blog.


I never thought I'd see myself writing the above.. :(


#12 ditdingiscool

ditdingiscool

    GMC Member

  • New Member
  • 335 posts

Posted 09 March 2009 - 05:52 PM

NEAT!!! i was just thinking 'bout that today, man thats cool, testing it now...
  • 0

#13 newbie013

newbie013

    GMC Member

  • GMC Member
  • 96 posts
  • Version:GM8

Posted 17 March 2009 - 02:20 PM

Can this dll load mutiple lua scripts at one time.??
  • 0

#14 ditdingiscool

ditdingiscool

    GMC Member

  • New Member
  • 335 posts

Posted 17 March 2009 - 04:47 PM

Can this dll load mutiple lua scripts at one time.??

yes, but one script has to finish before you start the next one,


EDIT:for some reason, two scripts running at the same time will mess up, i registered a function to change the speed off the calling object, and i have two off those objects, both with a different script, but their speed ends up the same(while one should be 5 and the other should be 1)

oh, and it would be nice if you could make your own error dialog...

Edited by ditdingiscool, 17 March 2009 - 05:06 PM.

  • 0

#15 newbie013

newbie013

    GMC Member

  • GMC Member
  • 96 posts
  • Version:GM8

Posted 17 March 2009 - 06:15 PM

lua_event gives me the whole time a unexpected error. :D
  • 0

#16 ditdingiscool

ditdingiscool

    GMC Member

  • New Member
  • 335 posts

Posted 19 March 2009 - 03:07 PM

lua_event gives me the whole time a unexpected error. :lol:

weird... are you using gm7?
  • 0

#17 Tahnok

Tahnok

    Friendly Madman

  • GMC Member
  • 1854 posts
  • Version:GM:Studio

Posted 19 March 2009 - 10:32 PM

This is a really fascinating DLL. It could really allow for some in-depth user mods to games. However, the buggyness people are experiencing makes me hesitant to use it in a serious project.

On my PC, opening the gm6 example in GM6 results in the game freezing when a script is called. Opening the same GM6 file in GM7 works perfectly.

Edit: Opening the LOL example in GM6 gives me an actual "unexpected error" error message. Opening it in GM7 works perfectly. So it appears its still rather buggy in GM6.

Edited by Tahnok, 20 March 2009 - 12:05 AM.

  • 0

gmc_signature.png


#18 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 20 March 2009 - 03:17 AM

Damn it! I forgot, that works only with GM 7

Maybe your 'fix' wasn't too good.

What was this DLL made in? Can you give us (or me) some more information about the exported functions?
  • 0

#19 Mailas

Mailas

    Send in the Mail

  • GMC Member
  • 5900 posts
  • Version:GM:Studio

Posted 21 March 2009 - 11:56 PM

Oh wow! I've been waiting for something like this for a while! Thanks a bunch!!
Please do add an example, I would like to see how it works.
  • 0

omQasih.jpg


#20 newbie013

newbie013

    GMC Member

  • GMC Member
  • 96 posts
  • Version:GM8

Posted 22 March 2009 - 11:57 AM

I've tryed to change dll_cdecall to dll_stdcall but that doesn't work. I'm still keeping unexpected error in gm6 :)
  • 0

#21 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 22 March 2009 - 01:09 PM

Umm, why? You don't need to do that.
  • 0

#22 newbie013

newbie013

    GMC Member

  • GMC Member
  • 96 posts
  • Version:GM8

Posted 22 March 2009 - 02:10 PM

Umm, why? You don't need to do that.


Maybe because I don't wanna have that stupid error :) ??
  • 0

#23 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 22 March 2009 - 02:35 PM

What error?

I don't get it, the EXE works, but the editable don't. This only works in GM7.

Edited by GMREC1111, 22 March 2009 - 05:01 PM.

  • 0

#24 newbie013

newbie013

    GMC Member

  • GMC Member
  • 96 posts
  • Version:GM8

Posted 23 March 2009 - 06:49 AM

the lua_event function gives me a unexspected error <_< in gm6 :whistle:
  • 0

#25 Tahnok

Tahnok

    Friendly Madman

  • GMC Member
  • 1854 posts
  • Version:GM:Studio

Posted 24 March 2009 - 10:03 AM

I don't get it, the EXE works, but the editable don't. This only works in GM7.

I would have to guess then that the exe was actually created in GM7, especially since he added GM6 support as an after thought it would seem.

So has anyone had any problems using this with GM7? I would like to know it's at least stable for GM7 before I start implementing it into anything.
  • 0

gmc_signature.png


#26 ditdingiscool

ditdingiscool

    GMC Member

  • New Member
  • 335 posts

Posted 24 March 2009 - 01:59 PM

I don't get it, the EXE works, but the editable don't. This only works in GM7.

I would have to guess then that the exe was actually created in GM7, especially since he added GM6 support as an after thought it would seem.

So has anyone had any problems using this with GM7? I would like to know it's at least stable for GM7 before I start implementing it into anything.

almost no problems, if you don't intend to use two scripts at the same time there are no problems at all...
  • 0

#27 Kofel

Kofel

    GMC Member

  • New Member
  • 50 posts

Posted 25 March 2009 - 04:44 PM

For now that only works with GM7, i waiting for Snake's, he'll give me fixed version of his GMAPI which may work with GM6, so I'll post if I done new version with nice example. ( including all GM functions for Lua )
  • 0

#28 newbie013

newbie013

    GMC Member

  • GMC Member
  • 96 posts
  • Version:GM8

Posted 25 March 2009 - 05:41 PM

thx men :)
  • 0

#29 Tahnok

Tahnok

    Friendly Madman

  • GMC Member
  • 1854 posts
  • Version:GM:Studio

Posted 26 March 2009 - 03:51 AM

For now that only works with GM7, i waiting for Snake's, he'll give me fixed version of his GMAPI which may work with GM6, so I'll post if I done new version with nice example. ( including all GM functions for Lua )

Sounds very nice. I look forward to the update.
  • 0

gmc_signature.png


#30 Kofel

Kofel

    GMC Member

  • New Member
  • 50 posts

Posted 27 March 2009 - 10:05 AM

Ok, first post is updated.

  • GM functions included
  • Source code
  • GM6 support
  • Example ( GM6 and GM7 )

Thanks. ;d
  • 0

#31 newbie013

newbie013

    GMC Member

  • GMC Member
  • 96 posts
  • Version:GM8

Posted 27 March 2009 - 06:37 PM

the lua_init function gives me now 3 unexpected errors.
  • 0

#32 Kofel

Kofel

    GMC Member

  • New Member
  • 50 posts

Posted 27 March 2009 - 09:19 PM

I have compiled that DLL in debug configuration, ( nevermind why :( ) tommorow I will upload correct version.
Yours, Kofel.
  • 0

#33 Kofel

Kofel

    GMC Member

  • New Member
  • 50 posts

Posted 27 March 2009 - 11:07 PM

Okay, sorry for double post.

Check previous link, I have fixed all ERRORS, tested under GM6 and GM7. Please test. ;s
  • 0

#34 Sindarin

Sindarin

    Indie Game Developer

  • New Member
  • 1644 posts
  • Version:GM:HTML5

Posted 28 March 2009 - 12:11 AM

knowing little about Lua, does it have any video functions available?
  • 0
GM 8.1 / GM:HTML5 User

#35 Kofel

Kofel

    GMC Member

  • New Member
  • 50 posts

Posted 28 March 2009 - 08:19 AM

What problem with download an example? >.>
  • 0

#36 newbie013

newbie013

    GMC Member

  • GMC Member
  • 96 posts
  • Version:GM8

Posted 30 March 2009 - 03:45 PM

Yes it works now on gm6 :rolleyes: but how do I pass from gm6 to lua a string down. Only numbers are working :D
  • 0

#37 Kofel

Kofel

    GMC Member

  • New Member
  • 50 posts

Posted 30 March 2009 - 08:41 PM

newbie013, I'll check it ;>
  • 0

#38 Kofel

Kofel

    GMC Member

  • New Member
  • 50 posts

Posted 31 March 2009 - 06:49 AM

Okay, I uploaded that with fixed strings issue. :P
  • 0

#39 newbie013

newbie013

    GMC Member

  • GMC Member
  • 96 posts
  • Version:GM8

Posted 31 March 2009 - 03:49 PM

Thx strings work now proparly (I think). I try to use gm functions inside lua, it works quite well (with drawing funtions like that) but when I tryed to use the dll functions from gm I get some errors (it thinks that external_define is a variable :P )
  • 0

#40 Kofel

Kofel

    GMC Member

  • New Member
  • 50 posts

Posted 31 March 2009 - 05:59 PM

You wanna call external_call in Lua script?
  • 0

#41 newbie013

newbie013

    GMC Member

  • GMC Member
  • 96 posts
  • Version:GM8

Posted 01 April 2009 - 02:44 PM

yes :) I wanna use the external_* functions from game maker. Because I'm building a game maker like program with it with support for plugins and it would be nice if those also could use external_* functions. And maybe you also can make an option in the init function that de game maker functions are not usuable in lua files so I could load my replacement for the game maker functions :)
  • 0

#42 Kofel

Kofel

    GMC Member

  • New Member
  • 50 posts

Posted 01 April 2009 - 06:49 PM

I'll add some improvements like adding Gm functions what you want to GM.

For now you need to create script in Game Maker and hook it to Lua.
  • 0

#43 newbie013

newbie013

    GMC Member

  • GMC Member
  • 96 posts
  • Version:GM8

Posted 04 April 2009 - 12:01 PM

thx :P Any idea when you going to release a new version ? ;)
  • 0

#44 Kofel

Kofel

    GMC Member

  • New Member
  • 50 posts

Posted 05 April 2009 - 12:31 PM

For a while I don't have access to my PC and I am on a mac, I think to Thursday it will be done.

Edited by Kofel, 05 April 2009 - 12:32 PM.

  • 0

#45 Tahnok

Tahnok

    Friendly Madman

  • GMC Member
  • 1854 posts
  • Version:GM:Studio

Posted 06 April 2009 - 01:27 AM

I've had a chance to play around with the last release now a bit. Very nice indeed. There is one function missing though that would make things a lot easier. Right now the LUA scripts can access any script in-game if I'm not mistaken. A function to either blacklist or whitelist scripts from the LUA interface would be nice. Allowing access to every script is a security nightmare, especially in an online game.

It would be preferable I think if scripts were allowed and blocked somehow from within GM, because if they're blocked from within the dll the dll can easily be replaced, creating a larger security risk.
  • 0

gmc_signature.png


#46 Kofel

Kofel

    GMC Member

  • New Member
  • 50 posts

Posted 06 April 2009 - 11:19 AM

You are wrong. If you don't hook GM script ex. [b]test[b] you won't be able to call it in Lua code, so you need to use lua_register to do allow use.
  • 0

#47 Tahnok

Tahnok

    Friendly Madman

  • GMC Member
  • 1854 posts
  • Version:GM:Studio

Posted 06 April 2009 - 11:26 AM

You are wrong. If you don't hook GM script ex. [b]test[b] you won't be able to call it in Lua code, so you need to use lua_register to do allow use.

Holy cow, I can't believe I overlooked those function calls while trying to understand the example. Very nice indeed. It looks like my problem never really existed. I look forward to seeing what you come up with next!
  • 0

gmc_signature.png


#48 Kofel

Kofel

    GMC Member

  • New Member
  • 50 posts

Posted 06 April 2009 - 11:31 AM

You are wrong. If you don't hook GM script ex. [b]test[b] you won't be able to call it in Lua code, so you need to use lua_register to do allow use.

Holy cow, I can't believe I overlooked those function calls while trying to understand the example. Very nice indeed. It looks like my problem never really existed. I look forward to seeing what you come up with next!


Here you are, I might new version will be released at end of the week.
  • 0

#49 Hach-Que

Hach-Que

    RoketGames Admin

  • New Member
  • 1490 posts

Posted 06 April 2009 - 11:59 AM

Could you add a feature that allows us to register functions into tables?

That way we could call:

Namespace.MyFunction();

which would mean we could categorize functions :whistle:
  • 0

I don't visit these forums (and I haven't for quite some time). You can

see my latest community projects at the Redpoint Blog.


I never thought I'd see myself writing the above.. :(


#50 Kofel

Kofel

    GMC Member

  • New Member
  • 50 posts

Posted 06 April 2009 - 12:03 PM

If I'm not wrong Lua's doesn't support namespaces, nevermind. I have seen something like Space:function; I will look for it. I think if you use lua_register( instance, "Player:getName", player_getName ); you'll be able to use script in Lua Player:getName, :whistle:
  • 0