Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
brrant
Beginner


Joined: 19 Nov 2008
Posts: 14

PostPosted: Tue Nov 25, 2008 3:34 am   

Lua script - how to reference function stored in external file.
 
I'm trying to access a function stored in the file "split.lua" stored in "~\Lua\5.1\lua" I have most definitely verified that split.lua is in that directory.

The two code snippets are slightly different as in the second, I'm catching the value of varCurrSpells from a trigger (that does work) and in the first I'm just assigning that value to the variable.

I believe what I must need is a correction to how I'm attempting to get the interpreter in cmud to reference the external function file split.lua.

Any and all help appreciated. :)


This works in Ultraedit/Lua direct:
Code:
--Required Libraries
split=require('split')

varCurrSpells = "curse, poison, plague, dispel magic, counterspell"


tblCurrSpells = split(varCurrSpells, ", ", plain)

for j = 1,table.maxn(tblCurrSpells) do
    print(tblCurrSpells[j])
        end


Output is:
Code:
curse
poison
plague
dispel magic
counterspell


This does not work in Cmud, the trigger does not fire so long as the line "split=require('split') is enabled:
Code:
--Required Libraries
split=require('split')

zs.beep()
varCurrSpells = zs.param(1)

tblCurrSpells = split(varCurrSpells, ", ", plain)

for j = 1,table.maxn(tblCurrSpells) do
    print(tblCurrSpells[j])
        end
[/code]
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Tue Nov 25, 2008 4:32 am   
 
You need to put the split.lua file where CMUD's lua.dll can find it - I've not used this method myself yet, so I don't know quite where that'll be. If you follow this method and get it working, please tell me, because it's something I'm going to want to look at in the future for sure. The folder will either be your CMUD install directory, or your data directory, or perhaps a /lua/ subfolder in either of those.

A much easier method is to just put the code from split.lua into an OnConnect event that'll define its split() function in CMUD's Lua namespace. This won't work with more complex libraries using DLLs, but for simple stuff that just defines new functions using Lua code, you should have no problem.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
brrant
Beginner


Joined: 19 Nov 2008
Posts: 14

PostPosted: Tue Nov 25, 2008 5:16 am   
 
Copying the file "split.lua" to the install directory for cmud works.

Obviously this isn't ideal. The reason I went looking for a split function is because lua is missing the perl function by the same name. In other words, I plan to be using it a lot.

It's been years and years since I had to mess with updating PATH and the Vista approach to that is muddy. Or perhaps just overly specific. Still working on getting the ~\Lua\5.1\lua directory into the PATH value, at which point it looks like I'll be golden. While looking through path values, I see that UltraEdit chucked in quite a few values there, which I presume is why the script run via Ultraedit worked in the first place.

Cheers.
Reply with quote
intoK
Apprentice


Joined: 18 Feb 2007
Posts: 190

PostPosted: Tue Nov 25, 2008 9:00 am   
 
pluck in main package onload or so
package.path=package.path..";C:\\wherever\\?.lua"

or make subdir lua in cmuds exe dir, its in default search path
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net