ENIGMA Forums

Contributing to ENIGMA => Function Peer Review => Topic started by: WizzardMaker on February 08, 2015, 10:54:50 AM

Title: Lua Extension
Post by: WizzardMaker on February 08, 2015, 10:54:50 AM
Hello folks!
I used my free Weekend to create a Lua Extension for ENIGMA and it worked!
The extension is not finished, the only thing what it can do is open a Lua script and let it search for a variable called "returner" and it can execute a string filled with Lua code.

I will add functions to execute Lua scripts and let it return your variables and I try to add a function that will let Lua execute some GM functions.

Here are the functions that can be executed, what they do and what they need:
Code: [Select]
lua_execute_file(filename)
--filename = Thats the name + path to the Lua script
--What the function needs: It needs a lua script with a variable called "returner".
--What the function returns: It returns the variable "returner" from the Lua script, if the function cant find the variable "returner" or its not a string/integer the function will return "ERROR! UNKNOW RETURNER TYPE OR ERROR IN SCRIPT"
lua_execute_string(code)
--code = What do you think?
--What the function does: For now it does nothing... but I am trying to let the function do the same as lua_execute_file()

Here is the link to the repository of the Lua Extension: https://github.com/WizzardMaker/Lua-Extension

PS: I've written it so that it works, but I'll still have to clean it...
Title: Re: Lua Extension
Post by: TheExDeus on February 08, 2015, 02:19:58 PM
I'll look at it when you post the link. I'm still deciding on what scripting language I want to implement. I ain't big fan of Lua, but maybe it will suffice.
Title: Re: Lua Extension
Post by: WizzardMaker on February 09, 2015, 08:03:54 AM
So the link is up.
I decided to use Lua because I know it, I know the syntax and I know how it works.
I dont really know about other scripting languages and I didnt wanted to read a whole documentation about a new language so I used Lua.
You can make your own extension with another language :)
Title: Re: Lua Extension
Post by: WizzardMaker on February 10, 2015, 01:04:35 PM
For everybody who wants to install the Extension just copy the folders from the repository to your ENIGMA installation and start ENGIMA, for everybody who gets Syntax errors just check if you have enabled the function in the Game Settings under ENIGMA / Extensions
Title: Re: Lua Extension
Post by: WizzardMaker on February 13, 2015, 09:47:00 AM
I updated the Extension!
There are now functions to add GML functions into Lua
Here are all functions:

-
If there are functions that you want me to add just reply or send me a PM.
Title: Re: Lua Extension
Post by: WizzardMaker on March 01, 2015, 01:58:49 PM
The Lua Extension is "finished" (The code needs some cleanup :D) and ready to be used.
Just download from GitHub and follow my instructions on how to install it.

GitHub page: https://github.com/WizzardMaker/Lua-Extension

There are still some unknown warning messages from the Compiler which I have to fix but its ready to use!

I had to disable some functions, namely:
All of the extension functions (There will be support for it later but not for now)
and all of the functions with varargs as argument (Just look into the LGM function list in the build tab on the top)
and some of the buffer functions
other functions:
Code: [Select]
is_real();is_string();instance_change_inst();abs();min();max();median();
Title: Re: Lua Extension
Post by: daz on May 01, 2015, 02:59:59 AM
Hi. This is a very interesting project. Can you perhaps provide an example of how to use this? It's not immediately clear to me how this works... e.g. for events that only happen once, or events that happen periodically (draw / step).

Also what file formats work with it? Any as it uses simple GML commands?
Title: Re: Lua Extension
Post by: HitCoder on May 02, 2015, 07:40:17 AM
I'll look at it when you post the link. I'm still deciding on what scripting language I want to implement. I ain't big fan of Lua, but maybe it will suffice.

Actually, Lua is a really nice language, the only issue is it's simplism. As a matter of fact though, it's a really damn easy language to learn when it comes to code, so maybe if this is finished we can have games with easy modding support using a Lua interpreter...
Actually, the guide on making an extension in the wiki teaches with Lua, but I could never get that working... PLEASE keep up the work, you've got me really excited! ^^
Title: Re: Lua Extension
Post by: TheExDeus on May 02, 2015, 09:00:50 AM
I on the other hand cannot stand Lua syntax. I haven't looked at it that closely though. Maybe after a while you can stand to like it. I did make an AngelScript extension which I could post though. That language is very close to C++ and in turn EDL/GML.
Title: Re: Lua Extension
Post by: WizzardMaker on May 03, 2015, 04:23:07 AM
The Project got updated, there is now an example and some new functions to play with.

Just download the new .zip or update your version with Git.
If there are any questions feel free to ask!

And can somebody answer why the .exe is about 12 MB big when there is just an Object and a Room?
Title: Re: Lua Extension
Post by: TheExDeus on May 03, 2015, 07:07:03 AM
See what extensions are added and what systems are used. For example, OpenAL is about 3mb, so if you disable sound system, it will be smaller. Then did you try compiling with Compile option or the Debug/Run options? For me an empty game is 1.17mb.
Title: Re: Lua Extension
Post by: WizzardMaker on May 03, 2015, 01:56:03 PM
I just hit run ^^ and with every default extension turned on.

Another problem I do encounter is the tremendous amount of crashes and I don't know why
Title: Re: Lua Extension
Post by: TheExDeus on May 03, 2015, 08:24:38 PM
The default should still be much smaller than 12mb. Try disabling as much extensions as you can.

LGM was left in a very unstable state sadly. And we don't have Java dev's currently who could work on that. It seems I'm the only one still working on ENIGMA at the moment. Let's hope this is only temporary.
Title: Re: Lua Extension
Post by: sorlok_reaves on May 03, 2015, 10:07:53 PM
I pushed a patch to fix one of the problems with LGM, but it's not really my area of expertise.

If a particular crash scenario is causing you untold grief, try to narrow down the cause and I'll see what I can do to help. :)
Title: Re: Lua Extension
Post by: TheExDeus on May 04, 2015, 07:32:38 AM
Can you post the .jar somewhere? As Robert and Ism is missing, it would be good if the LGM fixes were still available to download if not in the repo. I personally have problems with LGM freezing when pressing the Run button (or Compile button, or the Debug button), as well as crashing the whole program (windows asks to End Task) when one of the buttons are pressed. So in one case a freeze happens when the ENIGMA plugin is called (LGM then uses 0% of CPU, so it doesn't seem to be stuck in an infinite loop without sleep), and in the second case it happens when the compilation starts (the console starts printing stuff). They are actually very easy to replicate, as I have these crashes on both PC's and they happen at least once every 5 or even less compiles. Sadly no log is created. Also, ENIGMA.exe seems to crash when I try to debug it in GDB (also when it's compiled in Debug mode). I'll see if I can find the cause of that.

But we should probably take this discussion elsewhere.
Title: Re: Lua Extension
Post by: sorlok_reaves on May 04, 2015, 09:46:39 PM
Ah, my fix was just for saving + loading with constants. LGM doesn't actually freeze that much on Linux. I can still post the jar if you want.

Are you sure that LGM is getting enough memory on Windows?

As a point of reference, I've never had LGM crash during either of the 2 Ludum Dares I did (so, 2 * 48h).
Title: Re: Lua Extension
Post by: TheExDeus on May 05, 2015, 10:25:33 AM
Maybe it's a Windows only bug. I haven't used LGM with Linux that much. Memory wise there shouldn't be a problem, as it crashes also when no project is opened. Just open LGM, add a room and press Run. At about 30% rate it will crash. And when it crashes with a an open project, the project doesn't need to be complicated. Here is a screenshot:
(http://i.imgur.com/vBdPmXD.png)
You can see it crashes at "Populating communication buffer". Memory is low (200mb) and the project is empty. In this case I had to compile the project 3 times until it crashed. The first two it didn't. On average it takes about three times, but it has happened on the first one as well. It does seem that the memory slightly increases every time I press Compile. Maybe some kind of memory leak? It doesn't allow me to debug in Windows, as the ENIGMA.exe doesn't even run then. And I don't know how to debug .jar's. Maybe on Linux regular wallgrind can do it?
Title: Re: Lua Extension
Post by: TheExDeus on May 10, 2015, 10:36:23 AM
I cannot find any information on why it keeps crashing. Sometimes it's so frustrating that it crashes 10 times in a row. It doesn't write any crash dump (maybe windows does?) and I cannot run any of it in some kind of debug mode. I think the problem is in either the JNA or the plugin, as the crashes happen ONLY when using the plugin buttons (Run, Compile etc.). But that means the .jar talks with another .jar and so it makes sense that I cannot debug it. Maybe someone with more Java knowledge can see what is up. Because the crashing is unbearable.

edit: The only windows log that is created is this: http://pastebin.com/3GT9hQ2f . I have a .egm that crashes every time on my PC (so I cannot run it at all), but runs fine on my laptop ("fine" meaning it crashes 50% of time, not 100%). When I save a .gmk I can get it to run with the 50% though.
Title: Re: Lua Extension
Post by: WizzardMaker on May 11, 2015, 04:43:52 AM
A possible way to fix it is to finish the cpp/c version of LGM, that would fix the problem and remove the need of java
Title: Re: Lua Extension
Post by: TheExDeus on May 11, 2015, 06:12:40 AM
You mean NaturalGM? Sadly we have problems with developers in this regard. Java was developed for almost 10 years or so, and thus it's not that easy to replicate all that very rapidly. If all else fail I will start creating an IDE in ENIGMA, but that will be slow and probably not really functional for a long time (especially if I make it alone). Right now I'm working on GUI stuff and fixing bugs in ENIGMA, but right now i'm the only one working on it.
Title: Re: Lua Extension
Post by: Darkstar2 on May 14, 2015, 01:48:29 PM
It is something I tried once doing and intended to, but I don't know the format used for the room data, it is all a mystery to me.  If I were to make an IDE though, I would use the same system as GMS, meaning use all your resources externally instead of saving everything packed in the project file.  Currently, the way enigma plugin works is that it takes whatever is loaded in memory and passes it along....it's ridiculous, I think GMS' has a better approach to handling this.

If we had a fully functional CLI it would greatly help to do an IDE.
Or even integrate that CLI to the current IDE and get rid of the current plugin, as definitely what is causing stability issues is NOT the IDE alone but the enigma plugin.  When using the LGM alone without the plugin it's a whole different ball game.
Title: Re: Lua Extension
Post by: Goombert on July 31, 2015, 12:59:36 AM
Was this merged into the main repo?

I've moved this temporarily down to Function Peer Review as I am not quite sure where it belongs on the board.
Title: Re: Lua Extension
Post by: TheExDeus on July 31, 2015, 04:40:38 PM
No, it is an extension and is not meant to be in main repo. It adds an additional dependency. We should have an additional way to share extensions trough some kind of extension database which could even be integrated in ENIGMA/LGM. But until more people are making extensions the forum suffices. I also have an AngelScript extension which I won't put in the repo. I haven't shared it here either though.
Title: Re: Lua Extension
Post by: HitCoder on September 05, 2015, 11:50:47 AM
error...

Code: [Select]
In file included from Universal_System/Extensions/Lua/lua.cpp:1:0:
Universal_System/Extensions/Lua/include.h:10:22: fatal error: LuaState.h: No such file or directory
 #include <LuaState.h>
                      ^
compilation terminated.
g++ -std=c++11 -Wall -s -O3 -fno-rtti -fno-exceptions -DPATH_EXT_SET -IPlatforms/xlib/Info -IGraphics_Systems/OpenGL1/Info -IAudio_Systems/OpenAL/Info -ICollision_Systems/Precise/Info -IWidget_Systems/None/Info -INetworking_Systems/None/Info -IUniversal_System/Info -I. -I/home/hitcoder/.enigma/ -Wall -s -O3 -fno-exceptions -fexceptions  -MMD -MP -c -o /home/hitcoder/.enigma/.eobjs/Linux/Linux/Run/SHELLmain.o SHELLmain.cpp
In file included from /home/hitcoder/.enigma/API_Switchboard.h:48:0,
                 from SHELLmain.cpp:60:
./Universal_System/Extensions/Lua/include.h:10:22: fatal error: LuaState.h: No such file or directory
 #include <LuaState.h>
                      ^
compilation terminated.
make[1]: Leaving directory `/home/hitcoder/enigma-dev/ENIGMAsystem/SHELL'
make: *** [Game] Error 2

sorry for large text dump :/

OS: Linux Mint XFCE 17.2
Title: Re: Lua Extension
Post by: WizzardMaker on September 06, 2015, 04:23:24 AM
The included files are all in the mingw folder of my repository and I dont have enigma on my linux so I dont know what your include folder is called, you could move/copy those files to the folder of the extension and rewrite the include line
Title: Re: Lua Extension
Post by: WizzardMaker on January 11, 2016, 04:10:50 PM
Its been a long time since somebody replied to this topic, and I want to know if there is something I should do with this extension, if somebody is using it, or if its utterly broken but no one wants to tell me.
Title: Re: Lua Extension
Post by: HitCoder on January 11, 2016, 04:43:47 PM
Been unable to use it as I haven't opened Enigma for weeks, been messing with visual studio, but if I get the opportunity I'll take a look in the next couple of days.
Title: Re: Lua Extension
Post by: Garo on January 12, 2016, 01:30:00 PM
I gave it a try. I several things and it seemed to finally work when I moved the folder from Additional to usr. Unfortunately it seems that the static library files weren't compatible with Linux.
Title: Re: Lua Extension
Post by: WizzardMaker on January 13, 2016, 12:39:11 AM
Yeah, Linux is something I cant really try as I dont have a stable linux machine. I will try to fix some problems using a VM