[How-To] Notepad++ Syntax Highlighting Metin2 Quests Lua

12/25/2016 02:11 lollo_9_1#1
[How-To] Notepad++ Syntax Highlighting Metin2 Quests Lua
After a while, I found back my modded notepad++ langs.xml containing all the old metin2 lua functions in there.

It's dated 2012 (I've added the recent langs.xml lua tags few hours ago for lua 5.2 as well), but I'll update it soon with the 40k functions and mine as well. (on github)

How to "install" it?

Well, open %appdata%\Notepad++\langs.xml and replace the <Language name="lua" ...> section with this: [Only registered and activated users can see links. Click Here To Register...] (it doesn't allow me to use <!-- --> comments though)

After that, restart notepad++, and it's done.

Result: [Only registered and activated users can see links. Click Here To Register...]

Enjoy your Christmas Abione.

Note: Some people should already have tried to do so in the past, but this is the nicest way I like.
12/26/2016 15:32 lollo_9_1#2
Updated on github with the 40k functions as well. (and also others used by me)

[Only registered and activated users can see links. Click Here To Register...]

Note: Also added some dumplist examples.
12/26/2016 19:16 rollback#3
Quote:
Originally Posted by lollo_9_1 View Post
Updated on github with the 40k functions as well. (and also others used by me)

[Only registered and activated users can see links. Click Here To Register...]

Note: Also added some dumplist examples.
Here's an example how you can dump all global functions without using an lookup table
Code:
local function dumpFunctions(tbl, done, preStr)
	local functions = {}
	local done = done or {tbl}
	local preStr = preStr or ""
	
	for k, v in pairs(tbl) do
		local path = ""
		if preStr == "" then
			path = k
		else
			path = string.format("%s.%s", preStr, k)
		end
		
		if type(v) == "function" then
			table.insert(functions, path)
		elseif type(v) == "table" then
			local currentTableAlreadyDone = false
			for _, tbl in ipairs(done) do
				if tbl == v then
					currentTableAlreadyDone = true
					break
				end
			end
			
			if not currentTableAlreadyDone then
				table.insert(done, v)
				
				for _, functionName in ipairs(dumpFunctions(v, done, path)) do
					table.insert(functions, functionName)
				end
			end
		end
	end
	
	return functions
end

local functions = dumpFunctions(_G)
for _, functionName in ipairs(functions) do
	print(functionName)
end
12/26/2016 20:51 lollo_9_1#4
Quote:
Originally Posted by rollback View Post
Here's an example how you can dump all global functions without using an lookup table
Code:
local function dumpFunctions(tbl, done, preStr)
	local functions = {}
	local done = done or {tbl}
	local preStr = preStr or ""
	
	for k, v in pairs(tbl) do
		local path = ""
		if preStr == "" then
			path = k
		else
			path = string.format("%s.%s", preStr, k)
		end
		
		if type(v) == "function" then
			table.insert(functions, path)
		elseif type(v) == "table" then
			local currentTableAlreadyDone = false
			for _, tbl in ipairs(done) do
				if tbl == v then
					currentTableAlreadyDone = true
					break
				end
			end
			
			if not currentTableAlreadyDone then
				table.insert(done, v)
				
				for _, functionName in ipairs(dumpFunctions(v, done, path)) do
					table.insert(functions, functionName)
				end
			end
		end
	end
	
	return functions
end

local functions = dumpFunctions(_G)
for _, functionName in ipairs(functions) do
	print(functionName)
end
Don't forget to sort it before the for loop:
table.sort(functions)
The only problem doing it like this is that it will add a little of junk as well. (and we also need to separate the built-in methods from the metin2's ones)

It would be perfect for quest_functions though. It would become like this:
Code:
local function dumpFunctions(tbl, done, preStr)
	local functions = {}
	local done = done or {tbl}
	local preStr = preStr or ""

	for k, v in pairs(tbl) do
		local path = ""
		if preStr == "" then
			path = k
		else
			path = string.format("%s.%s", preStr, k)
		end

		if type(v) == "function" then
			table.insert(functions, path)
		elseif type(v) == "table" then
			local currentTableAlreadyDone = false
			for _, tbl in ipairs(done) do
				if tbl == v then
					currentTableAlreadyDone = true
					break
				end
			end

			if not currentTableAlreadyDone then
				table.insert(done, v)

				for _, functionName in ipairs(dumpFunctions(v, done, path)) do
					table.insert(functions, functionName)
				end
			end
		end
	end

	return functions
end

local functions = dumpFunctions(_G)
table.sort(functions)

local outFile = assert(io.open("quest_functions", "w"))
for _, functionName in ipairs(functions) do
	outFile:write(functionName.."\n")
end
assert(outFile:close())