| Posts | ||
|---|---|---|
| [Source ] Adding Lua (Forums : Coding & Scripting : [Source ] Adding Lua) | Post Reply | |
| Thread Options | 1 2 | |
| Jun 30 2009, 8:37am Anchor | ||
|
Hi! greetz, |
||
| Jun 30 2009, 11:19am Anchor | ||
|
There is a new tutorial for adding lua up on the wiki it uses a newer version of lua if I am not mistaken and doesn't use luabind. I recommend you check that out. |
||
|
|
Jun 30 2009, 11:25am Anchor | |
|
It was writen by me, feel free to ask any questions here about it. -- "To me, solving problems is a bit like a drug. You’re on it, and you can’t get off." |
||
| Jun 30 2009, 2:12pm Anchor | ||
|
Ok, i tried it, but couldn't get that interface thingy to work. Could you help me alittle? |
||
|
|
Jun 30 2009, 9:53pm Anchor | |
|
Well you need to tell me what you have done and what errors your getting. -- "To me, solving problems is a bit like a drug. You’re on it, and you can’t get off." |
||
| Jul 2 2009, 9:08am Anchor | ||
|
Well, may problem's a little more generic. It's just that the description "Now you can make a lua interface" is alittle vague. I mean, what is implemented and what do i have to implement? |
||
| Jul 2 2009, 9:38am Anchor | ||
|
I've also been using the "Adding Lua" tutorial and have been having some trouble with it. Firstly, I'm very greatful you put up a tutorial on Lua. Thanks You say "You will need to make your own class that inherets from LuaHandle ..." and "And thus you will need to define this functions in another file". Would it be possible to instead include complete examples of these files in the wiki as you did with the ge_luamanager files? That would be really helpful. Thanks |
||
|
|
Jul 2 2009, 10:01am Anchor | |
|
The reason i dont include complete versions of these is because they will be dependent on what you want to do. So the first thing you need to do is make a new class that inherits from LuaHandle
Next thing to do is make a constructor and the 4 functions you need to override
Now you need to make sure your constuctor calls Register so in a cpp file start the class def:
and implment the other functions like on the wiki. So what you have to do is dependent on what you want to do. You have to provide the mapping between c++ and lua in the form of functions (lua calls into c++) and callbacks (c++ calls into lua). If you tell me what your trying to do i could help a bit better. Edited by: lodle |
||
| Jul 2 2009, 10:55am Anchor | ||
|
Omg! Epic post! please add to wiki! Add an example of how to have lua register a C++ func and You're perfecx! |
||
|
|
Jul 2 2009, 11:03am Anchor | |
|
This is on the wiki all ready plus that as well! Look at the 4 functions i have there and read the text! Edited by: lodle |
||
| Jul 2 2009, 11:16am Anchor | ||
|
kk, guess that be my bad. Well, then I'll be on programming a lua base Edited by: Drake25 |
||
| Jul 2 2009, 12:48pm Anchor | ||
|
When I get this all working, I'll update the wiki page a little. I got it all to compile, now I just need to have Lua functions called in C++ and C++ functions called in Lua. Two quick questions before I go off and try that. In the init function, you call a lua file like so:
1. What location is this looking for the file? SourceMods/MyMod? p.s. For other guys who haven't been able to get it to compile, here's my stuff so far: myluamanager.h
myluamanager.cpp (I added in a Msg call to see if it reached that far. You can remove that when you're sure it's running)
I added them both in server/source files Edited by: SecretiveLoon |
||
|
|
Jul 2 2009, 10:06pm Anchor | |
|
You dont need to have lua_State *pL; in your class as this is part of LuaHandle (use GetLua() to get the lua handle) but besides that it looks fine. Here is an example script we use for ges: Wiki.goldeneyesource.net and yeah that will look for the file in your mod folder. -- "To me, solving problems is a bit like a drug. You’re on it, and you can’t get off." |
||
| Jul 3 2009, 9:27am Anchor | ||
|
Wait, I'm missing something. Do i now have to make sepperate Lua functions in C++ or are they already their? (Before i continue programming to death) |
||
| Jul 3 2009, 10:16am Anchor | ||
|
It looks like the ones that already have global scope (such as Msg) just have to use the REG_FUNCTION define. Trying to access something in a class like GetMotor in ai_basenpc.cpp seems to require making a new function ... which seems to defeat the purpose a little to me. I'm hoping my understanding of Lua is just flawed here. I can't figure out how else folks could get Lua to do anything useful in non-open source games like DoW or WoW. I hope to God I'm wrong. |
||
|
|
Jul 3 2009, 10:34am Anchor | |
|
You have to make mappings from c++ to lua other wise how the hell does lua now what to do? Read the lua docs and look at my 4 examples there. -- "To me, solving problems is a bit like a drug. You’re on it, and you can’t get off." |
||
| Jul 3 2009, 10:36am Anchor | ||
|
Great. ok, then I'm on trying my best to connect.... |
||
|
|
Jul 3 2009, 10:26pm Anchor | |
|
The same way every one else does, code the mappings. -- "To me, solving problems is a bit like a drug. You’re on it, and you can’t get off." |
||
|
|
Jul 6 2009, 6:20pm Anchor | |
|
Hey Lodle, I've been getting errors when trying to compile with your tutorial. Error wrote:1>MSVCRT.lib(MSVCR80.dll) : error LNK2005: _rand already defined in randoverride.obj
1>MSVCRT.lib(MSVCR80.dll) : error LNK2005: _srand already defined in randoverride.obj 1>MSVCRT.lib(MSVCR80.dll) : error LNK2005: _realloc already defined in memoverride.obj 1>MSVCRT.lib(MSVCR80.dll) : error LNK2005: _free already defined in memoverride.obj Any ideas? I compiled the LUA 5.1 Lib and added it to the project and followed the rest of the tutorial. -- Jordan Nolan |
||
|
|
Jul 6 2009, 8:46pm Anchor | |
|
Make sure the lua lib is compiled using Multi thread lib (prop -> c++ -> code gen -> runtime lib should be /MT) -- "To me, solving problems is a bit like a drug. You’re on it, and you can’t get off." |
||
|
|
Jul 6 2009, 11:26pm Anchor | |
|
That fixed those errors, but when I compile again I get more. Its never ending :P 1>LIBCMT.lib(crtheap.obj) : error LNK2005: __calloc_crt already defined in memoverride.obj -- Jordan Nolan |
||
|
|
Jul 7 2009, 12:46am Anchor | |
|
ignore the lib LIBCMT when compiling lua -- "To me, solving problems is a bit like a drug. You’re on it, and you can’t get off." |
||
| Jul 13 2009, 11:44am Anchor | ||
|
Hello, when i try to compile, i get this error: C:\\?????\src\dlls\myluahandle.h(7) : fatal error C1083: Cannot open include file: 'ge_luamanager.h': No such file or directory ge_luamanager.cpp C:\\?????\adding lua to mod\ge_luamanager.h(20) : fatal error C1083: Cannot open include file: 'lua.h': No such file or directory Any help would be appreciated |
||
|
|
Jul 13 2009, 6:01pm Anchor | |
|
Where did you put your ge_luamanager and did you include the lua5.1 include folder? -- Jordan Nolan |
||
| Jul 26 2009, 2:09pm Anchor | ||
|
I have added ge_luamanager but also i've added lua.h to the same folder but i still get errors that it cant find it. |
||
Only registered members can share their thoughts. So come on! Join the community today (totally free) and join in the conversation.