Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

[suggestion] Community LUA Library

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> [suggestion] Community LUA Library Page: [1]
Login
Message << Older Topic   Newer Topic >>
[suggestion] Community LUA Library - 12/18/2014 8:47:02 PM   
snowburn


Posts: 188
Joined: 9/24/2013
From: Bovril, Argentina
Status: offline
Hello!!

i've downloaded v1.06 and its a giant step forward, congratulation to all the devs :)
i think its time for us (the players) to create a lua library which the most used functions to simplify scenario creation.

for example:

How to assign a possibly dead unit to a mission.
Author: Baloogan
quote:

function AddToMission(side_name,unit_name,mission_name)
local unit = ScenEdit_GetUnit({side=side_name,name=unit_name})
if unit ~= nil then
unit.mission = mission_name
end
end




This is a library for making using GetKeyValue and SetKeyValue easier. It allows you to use persisted values through a simple tablelike interface
Author: ckfinite
quote:

KeyStore = {
keys = {
},
demarshallers = {
prim_str = function(strval) return strval end,
prim_num = function(strval) return tonumber(strval) end,
prim_nil = function(strval) return nil end,
prim_bool= function(strval) return strval=="true" end,
prim_func= function(strval) return nil end,
prim_tab = function(strval) return nil end
}
}

--metatable
local persister = {}

local function contains(t, e)
for i = 1,#t do
if t == e then return true end
end
return false
end

function persister.__index(table, key)
local result = ScenEdit_GetKeyValue(key)

if result == nil then
return nil
end

if (string.sub(result,1,1) == ":") then
--unmarshalled
return string.sub(result,2)
else
local slen,val = string.match(result,"([0-9]+):(.*)")
local nlen = tonumber(slen)
local demarshal_name = string.sub(val,1,nlen)
local demarshaller = table.demarshallers[demarshal_name]
return demarshaller(string.sub(val,nlen+1))
end
end

function persister.__newindex(_table,key,value)
function marshal(value)
local mt = getmetatable(value)
local name,marshalled = nil,nil
if mt == nil or (mt ~= nil and mt.__marshal == nil) then
if type(value) == "string" then
name,marshalled = "prim_str",value
elseif type(value) == "number" then
name,marshalled = "prim_num",tostring(value)
elseif type(value) == "nil" then
name,marshalled = "prim_nil",""
elseif type(value) == "boolean" then
name,marshalled = "prim_bool",tostring(value)
elseif type(value) == "function" then
name,marshalled = "prim_func","" --TODO
elseif type(value) == "table" then
name,marshalled = "prim_tab","" --TODO
else
name,marshalled = "prim_str",tostring(value) --default to str
end
end

if mt ~= nil and mt.__marshal ~= nil then
name,marshalled = mt.__marshal(value)
name = "mrsh_" .. name
end
return string.len(name) .. ":" .. name .. marshalled
end

if contains(_table.keys,key) then
ScenEdit_SetKeyValue(key,marshal(value))
else
table.insert(_table.keys, key)
ScenEdit_SetKeyValue(key,marshal(value))
end
end

function persister.__call(table, key, demarshaller)
table.demarshallers["mrsh_" .. key] = demarshaller
end

setmetatable(KeyStore, persister)


< Message edited by snowburn -- 12/18/2014 9:50:42 PM >
Post #: 1
RE: [suggestion] Community LUA Library - 12/18/2014 9:04:04 PM   
ckfinite

 

Posts: 377
Joined: 7/20/2013
Status: offline
There's moves afoot to make a package manager-like system. For now, though, I'll be posting my work on Baloogan's forum and on a to-be-created Github repository, which would be a better way to connect to it, especially because that library code has a nasty bug in it.

(in reply to snowburn)
Post #: 2
RE: [suggestion] Community LUA Library - 12/18/2014 9:06:09 PM   
snowburn


Posts: 188
Joined: 9/24/2013
From: Bovril, Argentina
Status: offline
a Github repository is an excellent idea

< Message edited by snowburn -- 12/18/2014 10:06:53 PM >

(in reply to ckfinite)
Post #: 3
Page:   [1]
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> [suggestion] Community LUA Library Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI

0.129