/*
dll file must using same folder's dll,
X:/xx/xxx/my_dll.dll
O:/ooo/oo/my_dll.dll
my_dll.dll =content= mydll.dll
but loading to memory , it's two different dll.
*/
/* below is dll key function and compiler option */
/*
compiler option : Enable microsoft extension , calling conv: __cdecl
*/
#pragma data_seg(".shared")
int share_var_k = 0;
#pragma data_seg()
#pragma comment(linker, "/section:.shared,RWS")
DLLAPI int WINAPI get_share_var(void)
{
return share_var_k;
}
DLLAPI void WINAPI set_share_var(int value)
{
share_var_k = value;
}
/* ---- cut ---- */
/* -------------- below is test file function ------*/
int main(int argc, char *argv[])
{
printf("Hello, world!\n");
for(int i=0;i<25 br="" i=""> {
int value=0;
set_share_var(i);
Sleep(1000);
value = get_share_var();
printf("%d\r\n",value);
}
return 0;25>
2014年10月26日 星期日
2014年10月18日 星期六
lcc-win32 build openeuolua
build a openeuolua.dll for
work for LFW LuaForWindows_v5.1.4-46.exe (from goggle code)
in OpenEUOLua.zip OpenEUOLua.txt copy rename to --> openeuolua.c
; make an lib for lcc-win32 usage
copy X:\lua\5.1\lib\lua51.lib
pedump /EXP lua51.lib > 51.exp
buildlib 51.exp lua51_lcc.lib
makefile
[code]
SRCDIR=e:\lcc\p\openeuolua
CFLAGS=-I"E:\lcc\p\OpenEUOLua\lua51\include" -I"e:\lcc\include" -DWIN32 -DLUA_BUILD_AS_DLL
CC=$(LCCROOT)\bin\lcc.exe
LINKER=$(LCCROOT)\bin\lcclnk.exe
OBJS=\
openeuolua.obj
LIBS=e:\lcc\p\openeuolua\lua51_lcc.lib
EXE=e:\lua\5.1\clibs\openeuolua.dll
$(EXE): $(OBJS) Makefile
$(LINKER) -s -dll -entry DllMain -nounderscores -o e:\lua\5.1\clibs\openeuolua.dll $(OBJS) $(LIBS)
# Build openeuolua.c
OPENEUOLUA_C=\
$(SRCDIR)\lua51\include\lauxlib.h\
$(SRCDIR)\lua51\include\lua.h\
$(SRCDIR)\lua51\include\luaconf.h\
openeuolua.obj: $(OPENEUOLUA_C) $(SRCDIR)\openeuolua.c
$(CC) -c $(CFLAGS) $(SRCDIR)\openeuolua.c
link:
$(LINKER) -s -dll -entry DllMain -nounderscores -o e:\lua\5.1\clibs\openeuolua.dll $(OBJS) $(LIBS)
clean:
del $(OBJS) openeuolua.dll
[/code]
build lua dll module in mingw/msys
1. install mingw/msys , base_mingw,base_msys,g++
2. postinstall msys
3. download & build lua 5.1.5
make mingw
4. write a dll4lua.c
gcc -O2 -c -o dll4lua.o dll4lua.c
gcc -O -shared -o dll4lua.dll dll4lua.o -llua
2. postinstall msys
3. download & build lua 5.1.5
make mingw
4. write a dll4lua.c
gcc -O2 -c -o dll4lua.o dll4lua.c
gcc -O -shared -o dll4lua.dll dll4lua.o -llua
2014年10月16日 星期四
xpsp3 install mingw using mingw-get-setup , after download ok , need run postinstall script/batch file
as title say:
When online install msys + mingw , using mingw-get-setup
after install ok , need to run postinstall script, otherwise
msys.bat environment don't recongnize your mingw tool-chain.
When online install msys + mingw , using mingw-get-setup
after install ok , need to run postinstall script, otherwise
msys.bat environment don't recongnize your mingw tool-chain.
2014年10月13日 星期一
LUA read only table
-----------------------------------------------
-- file DIR.lua
function readOnly (table)
local proxy = {}
local mt = { -- create metatable
__index = table
,__newindex = function (x,k,v)
error("read-only "..k, 2)
end
,__metatable = false
}
setmetatable(proxy, mt)
return proxy
end
local t = { LEFT = 7, RIGHT = 8 }
DIR = readOnly(t)
---------------------------------------------
-- file test.lua
dofile("DIR.lua")
print("t="..tostring(t))
print("LEFT="..DIR.LEFT)
-- DIR.LEFT = 9 -- : read-only LEFT
print("LEFT="..DIR.LEFT)
mt = getmetatable(DIR)
print("mt="..tostring(mt))
---------------------------------------------
-- output
t=nil
LEFT=7
LEFT=7
mt=false
-- file DIR.lua
function readOnly (table)
local proxy = {}
local mt = { -- create metatable
__index = table
,__newindex = function (x,k,v)
error("read-only "..k, 2)
end
,__metatable = false
}
setmetatable(proxy, mt)
return proxy
end
local t = { LEFT = 7, RIGHT = 8 }
DIR = readOnly(t)
---------------------------------------------
-- file test.lua
dofile("DIR.lua")
print("t="..tostring(t))
print("LEFT="..DIR.LEFT)
-- DIR.LEFT = 9 -- : read-only LEFT
print("LEFT="..DIR.LEFT)
mt = getmetatable(DIR)
print("mt="..tostring(mt))
---------------------------------------------
-- output
t=nil
LEFT=7
LEFT=7
mt=false
LUA Point class example 2
--
-- refine Point class for LUA
--
function class()
local cls = {}
cls.__index = cls
return setmetatable(cls,
{ __call = function (c, ...)
instance = setmetatable({}, cls)
if cls.__init then
cls.__init(instance, ...)
end
return instance
end
}
)
end
Point = class()
Point.key_list = {"x","y","z"}
function Point.__index(t,key)
error("No such Point member or init:"..key ,2)
end
function Point.__newindex(t,key,value)
for i = 1,#Point.key_list do
if key == Point.key_list[i] then
-- t[key] = value
rawset(t,key,value)
return
end
end
error("No such Point member :"..key ,2)
end
function Point:__init(...)
args = { ... }
if #args == 3 then
self.x = args[1]
self.y = args[2]
self.z = args[3]
elseif #args == 2 then
self.x = args[1]
self.y = args[2]
else
error("2D or 3D only" ,2)
end
end
function Point:__tostring()
local out = ""..self.x..","..self.y
local zz = rawget(self,"z")
if zz ~= nil then
out=out..","..self.z
end
return out
end
--
-- Usage
--
p1 = Point(1,2)
p2 = Point(3,4)
p1.x = 8
x1,y1=p1.x,p1.y
print(string.format("x1,y1=%d,%d",x1,y1))
-- p2 = p1
print(string.format("x2,y2=%d,%d",p2.x,p2.y))
--
local points = {p1,p2}
print("points[1].x=" .. points[1].x)
print("points[2].y=" .. points[2].y)
print("p1="..tostring(p1))
--print("p1="..p1)
p3 = Point(4,5,6)
print("p3="..tostring(p3))
--[[ below is two error test
print("p1.z="..p1.z) -- : No such Point member or init:z
p1.xxx = 567 -- : No such Point member :xxx
-- ]]
--
--[[ output
--
x1,y1=8,2
x2,y2=3,4
points[1].x=8
points[2].y=4
p1=8,2
p3=4,5,6
: No such Point member or init:z
: No such Point member :xxx
-- ]]
-- refine Point class for LUA
--
function class()
local cls = {}
cls.__index = cls
return setmetatable(cls,
{ __call = function (c, ...)
instance = setmetatable({}, cls)
if cls.__init then
cls.__init(instance, ...)
end
return instance
end
}
)
end
Point = class()
Point.key_list = {"x","y","z"}
function Point.__index(t,key)
error("No such Point member or init:"..key ,2)
end
function Point.__newindex(t,key,value)
for i = 1,#Point.key_list do
if key == Point.key_list[i] then
-- t[key] = value
rawset(t,key,value)
return
end
end
error("No such Point member :"..key ,2)
end
function Point:__init(...)
args = { ... }
if #args == 3 then
self.x = args[1]
self.y = args[2]
self.z = args[3]
elseif #args == 2 then
self.x = args[1]
self.y = args[2]
else
error("2D or 3D only" ,2)
end
end
function Point:__tostring()
local out = ""..self.x..","..self.y
local zz = rawget(self,"z")
if zz ~= nil then
out=out..","..self.z
end
return out
end
--
-- Usage
--
p1 = Point(1,2)
p2 = Point(3,4)
p1.x = 8
x1,y1=p1.x,p1.y
print(string.format("x1,y1=%d,%d",x1,y1))
-- p2 = p1
print(string.format("x2,y2=%d,%d",p2.x,p2.y))
--
local points = {p1,p2}
print("points[1].x=" .. points[1].x)
print("points[2].y=" .. points[2].y)
print("p1="..tostring(p1))
--print("p1="..p1)
p3 = Point(4,5,6)
print("p3="..tostring(p3))
--[[ below is two error test
print("p1.z="..p1.z) -- : No such Point member or init:z
p1.xxx = 567 -- : No such Point member :xxx
-- ]]
--
--[[ output
--
x1,y1=8,2
x2,y2=3,4
points[1].x=8
points[2].y=4
p1=8,2
p3=4,5,6
: No such Point member or init:z
: No such Point member :xxx
-- ]]
2014年10月12日 星期日
lua 2d/3d point class
--
-- define Point class for LUA
--
Point = {}
Point.key_list = {"x","y","z"}
function Point.__index(t,key)
error("No such Point member or init:"..key ,2)
end
function Point.__newindex(t,key,value)
for i = 1,#Point.key_list do
if key == Point.key_list[i] then
-- t[key] = value
rawset(t,key,value)
return
end
end
error("No such Point member :"..key ,2)
end
function Point.new(...)
local pt = {}
args = { ... }
if #args == 3 then
pt.x = args[1]
pt.y = args[2]
pt.z = args[3]
elseif #args == 2 then
pt.x = args[1]
pt.y = args[2]
else
error("2D or 3D only" ,2)
end
setmetatable(pt,Point)
return pt
end
--
-- Usage
--
p1 = Point.new(1,2)
p2 = Point.new(3,4)
p1.x = 8
x1,y1=p1.x,p1.y
print(string.format("x1,y1=%d,%d",x1,y1))
-- p2 = p1
print(string.format("x2,y2=%d,%d",p2.x,p2.y))
--
local points = {p1,p2}
print("points[1].x=" .. points[1].x)
print("points[2].y=" .. points[2].y)
-- [[ below is two error test
print("p1.z="..p1.z) -- : No such Point member or init:z
p1.xxx = 567 -- : No such Point member :xxx
-- ]]
--
--[[ output
--
x1,y1=8,2
x2,y2=3,4
points[1].x=8
points[2].y=4
: No such Point member or init:z
: No such Point member :xxx
-- ]]
-- define Point class for LUA
--
Point = {}
Point.key_list = {"x","y","z"}
function Point.__index(t,key)
error("No such Point member or init:"..key ,2)
end
function Point.__newindex(t,key,value)
for i = 1,#Point.key_list do
if key == Point.key_list[i] then
-- t[key] = value
rawset(t,key,value)
return
end
end
error("No such Point member :"..key ,2)
end
function Point.new(...)
local pt = {}
args = { ... }
if #args == 3 then
pt.x = args[1]
pt.y = args[2]
pt.z = args[3]
elseif #args == 2 then
pt.x = args[1]
pt.y = args[2]
else
error("2D or 3D only" ,2)
end
setmetatable(pt,Point)
return pt
end
--
-- Usage
--
p1 = Point.new(1,2)
p2 = Point.new(3,4)
p1.x = 8
x1,y1=p1.x,p1.y
print(string.format("x1,y1=%d,%d",x1,y1))
-- p2 = p1
print(string.format("x2,y2=%d,%d",p2.x,p2.y))
--
local points = {p1,p2}
print("points[1].x=" .. points[1].x)
print("points[2].y=" .. points[2].y)
-- [[ below is two error test
print("p1.z="..p1.z) -- : No such Point member or init:z
p1.xxx = 567 -- : No such Point member :xxx
-- ]]
--
--[[ output
--
x1,y1=8,2
x2,y2=3,4
points[1].x=8
points[2].y=4
: No such Point member or init:z
: No such Point member :xxx
-- ]]
2014年9月27日 星期六
lua queue example
[code]
queue = {}
function queue.new()
return { first = 1, last = 0 }
end
function queue.push( Q, value)
local last = Q.last + 1
Q.last = last
Q[last] = value
end
function queue.pop(Q)
local first = Q.first
local last = Q.last
if first > last then error("Q is empty") end
local value = Q[first]
Q[first] = nil
if first >= last then
Q.first = 1
Q.last = 0
else
Q.first = first + 1
end
return value
end
function queue.size(Q)
local first,last = Q.first,Q.last
print(string.format("(%d,%d)",first,last))
if (last < first) then return 0 end
return last-first+1
end
nq = queue.new()
print("q'size1="..queue.size(nq))
-- queue.pop(nq)
for i = 1, 10 ,2 do
queue.push( nq, i)
end
print("q'size2="..queue.size(nq))
for m = nq.first,nq.last do
print(""..m.."]="..nq[m])
end
print("first "..nq[nq.first])
local v
v = nq.first print(" v1 =".. v)
v = queue.pop(nq) print("pop = "..v)
v = nq.first print(" v2 =".. v)
v = queue.pop(nq) print("pop = "..v)
for m = nq.first,nq.last do
print(""..m.."]="..nq[m])
end
local n = queue.size(nq)
print("q'size3="..n)
for i=1,n do
v=queue.pop(nq)
print(""..i.."]="..v)
end
print("q'size4="..queue.size(nq))
print("#nq="..#nq)
[/code]
---- output ----
(1,0)
q'size1=0
(1,5)
q'size2=5
1]=1
2]=3
3]=5
4]=7
5]=9
first 1
v1 =1
pop = 1
v2 =2
pop = 3
3]=5
4]=7
5]=9
(3,5)
q'size3=3
1]=5
2]=7
3]=9
(1,0)
q'size4=0
#nq=0
queue = {}
function queue.new()
return { first = 1, last = 0 }
end
function queue.push( Q, value)
local last = Q.last + 1
Q.last = last
Q[last] = value
end
function queue.pop(Q)
local first = Q.first
local last = Q.last
if first > last then error("Q is empty") end
local value = Q[first]
Q[first] = nil
if first >= last then
Q.first = 1
Q.last = 0
else
Q.first = first + 1
end
return value
end
function queue.size(Q)
local first,last = Q.first,Q.last
print(string.format("(%d,%d)",first,last))
if (last < first) then return 0 end
return last-first+1
end
nq = queue.new()
print("q'size1="..queue.size(nq))
-- queue.pop(nq)
for i = 1, 10 ,2 do
queue.push( nq, i)
end
print("q'size2="..queue.size(nq))
for m = nq.first,nq.last do
print(""..m.."]="..nq[m])
end
print("first "..nq[nq.first])
local v
v = nq.first print(" v1 =".. v)
v = queue.pop(nq) print("pop = "..v)
v = nq.first print(" v2 =".. v)
v = queue.pop(nq) print("pop = "..v)
for m = nq.first,nq.last do
print(""..m.."]="..nq[m])
end
local n = queue.size(nq)
print("q'size3="..n)
for i=1,n do
v=queue.pop(nq)
print(""..i.."]="..v)
end
print("q'size4="..queue.size(nq))
print("#nq="..#nq)
[/code]
---- output ----
(1,0)
q'size1=0
(1,5)
q'size2=5
1]=1
2]=3
3]=5
4]=7
5]=9
first 1
v1 =1
pop = 1
v2 =2
pop = 3
3]=5
4]=7
5]=9
(3,5)
q'size3=3
1]=5
2]=7
3]=9
(1,0)
q'size4=0
#nq=0
2014年6月24日 星期二
-- LUA string.dump and loadstring usage
-- [[
function func_1()
print("I am func 1")
end
function func_2()
print("I am func 2")
end
-- [[
func_s = {}
func_s[1] = string.dump(func_1)
func_s[2] = string.dump(func_2)
-- ]]
print("output:")
for i=1,2 do
local exe = loadstring( func_s[i] )
exe()
end
stop()
-- ]]
--[[
output:
I am func 1
I am func 2
]]
訂閱:
意見 (Atom)
ubuntu kernel 5.4 pop noise (躁音) // 用 這條命令 可 暫時 關閉音效 省電模式, 但 重開機, 問題 仍在. $ sudo echo 0 > /sys/module/snd_hda_intel/parameters/power_s...
-
反同的意見大集結: 1. 應該保障,但是不能說同志婚的主張優於異性婚. 因為民主是算人頭的.需要溝通立法. 必需要消除異性婚的疑慮. 2. 立法院/政府應該推出認識同志的官方資料 並由學者專家認可.立法委員簽名認可. 簡單版/詳盡版. 不宜由同志組...
-
婚姻的意義 婚姻最大的目的是 鼓勵生養 . 對於國家而言,婚姻產生新的公民. 對於家族而言,婚姻延續家族的香火. 對於個人而言,婚姻有生兒育女的可能性. 對於社會而言,婚姻最能穩定家族的結構,(血親制度)確認彼此的關係. 而且在這種婚姻制度裏,個人是要有所犠牲,有所...
-
從愛的三角形,論 同性婚/異性婚 的優劣. 以下,單身是點,二人是線,親子是面(三角形). (絆的多少,對應到關係的穩定度, 愛,血親,收養,長相伴(習慣),性愛, 都可以形成不同程度的"絆". 若同性婚/ 異性婚無明顯差異,則不特別標明....