/*
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
-- ]]
訂閱:
文章 (Atom)
ubuntu kernel 5.4 pop noise (躁音) // 用 這條命令 可 暫時 關閉音效 省電模式, 但 重開機, 問題 仍在. $ sudo echo 0 > /sys/module/snd_hda_intel/parameters/power_s...
-
火箭隊 世堅 說: 中選會 最熱心了 。 是丫 ~ 東廠 ,西廠 為了 它們的 主子 ,最熱心了 。 連 睡覺 都在 想方設法 。
-
<style> ..... @media print { /* for page <div> */ .new-page-section { page-break-after: always; } } </style...
-
In Gvim ,How to setup default font and font-size In .gvimrc , You must add a ( \ ) back-slash to tell gvim , 16 is the font-size . Ot...