This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
char* errorInfo = (char*) errorBuffer->GetBufferPointer(); | |
const size_t cSize = strlen(errorInfo)+1; | |
wchar_t* wc = new wchar_t[cSize]; | |
size_t tmp = 0; | |
mbstowcs_s(&tmp, wc, cSize, errorInfo, cSize); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
__author__ = 'Administrator' | |
import test | |
import sys | |
class A(object): | |
haha = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" 在python里,默认参数值都是由函数进行引用的,所以前三个和最后一个函数调用使用的都是同一个默认的参数值""" | |
def foo(item, items=[], added=True): | |
if added: | |
items.append(item) | |
print items | |
foo(1) | |
foo(2) | |
foo(3, added=False) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
Lua is an interpreted language. So a variable(like function) | |
will be acessed only when it is executing. And it is better to write | |
a Module with a form of case three, because it has no need to do forward declaration | |
]] | |
-- case 1 | |
-- local fun2 | |
local function fun() | |
fun2() -- error, will call global fun2 not local fun2, and it is nil |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ 3 ways to call an instance's method ]] | |
Account = {balance = 0} | |
-- case 1 | |
function Account.withdraw (v) | |
Account.balance = Account.balance - v | |
end | |
-- case 2 | |
function Account.withdraw (self, v) | |
self.balance = self.balance - v |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
in b:deposit(), b.balance = b.balance + v. | |
In the left of equation, it mean initialize the file balance of object b, | |
and will not access the file in Account. but the right side will at the first. | |
After this, both side will access the filed in object b. | |
--]] | |
Account = {balance = 0} | |
function Account:deposit (v) | |
self.balance = self.balance + v |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local function printResult(a) | |
for i = 1, #a do | |
io.write(a[i], " ") | |
end | |
io.write("\n") | |
end | |
local function permgen (a, n) | |
n = n or #a | |
if n <= 1 then |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local function testRoutine() | |
co = coroutine.create(function (x) | |
for i = 1, 10 do | |
-- print("co", i) | |
coroutine.yield(i) | |
end | |
end) | |
print(coroutine.resume(co)) | |
print(coroutine.resume(co)) | |
print(coroutine.resume(co)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local function main() | |
i = 32 | |
local i = 0 | |
f = load(" i = i + 1; print(i)") | |
g = function () i = i + 1; print(i) end | |
f() | |
g() | |
end | |
main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function test() | |
x = 1 -- default is global | |
local y = 2 | |
end | |
local function main() | |
test() | |
print(x, y) | |
end |
NewerOlder